>_ IzzyLab

Hands-on task

This task is step 25 of the course “JSON, YAML and XML in the terminal”

Fix broken XML

medium~5 min

The file /root/broken.xml contains XML with an error — an unclosed tag, so xmllint considers it invalid. Fix the markup so the document becomes well-formed (xmllint --noout finishes without errors). Open the file in the Editor tab above the terminal, and check it with xmllint in the terminal.

What you'll practise:
  • xmllint
  • --noout
  • well-formed
  • XML validation
  • nesting

Topic breakdown

"Well-formed" XML is a document where every opening tag has a matching closing tag, tags are nested correctly (they don't overlap), there is a single root element and special characters are escaped properly (<, &). This is a more basic requirement than "valid" (conforming to a DTD/XSD schema). xmllint --noout checks exactly well-formedness and on an error prints the line and column, which makes it a quick linter for XML/HTML configs. The tool accepts streamed input as well as many files at once.

What's checked

  1. document is well-formed
  2. data preserved

What it looks like