Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created December 6, 2013 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbielawa/7829506 to your computer and use it in GitHub Desktop.
Save tbielawa/7829506 to your computer and use it in GitHub Desktop.
Example of bad XML in a DocBook 5 book and how to detect it with the xmllint command
# First we'll parse an invalid document
$ xmllint --noout --xinclude ./Virtual-Disk-Operations.xml
./Virtual-Disk-Operations.xml:13: parser error : Opening and ending tag mismatch: bar line 12 and foo
</foo>
^
./Virtual-Disk-Operations.xml:64: parser error : Opening and ending tag mismatch: foo line 11 and info
</info>
^
./Virtual-Disk-Operations.xml:79: parser error : Opening and ending tag mismatch: info line 6 and book
</book>
^
./Virtual-Disk-Operations.xml:80: parser error : Premature end of data in tag book line 2
^
$ echo $?
1
# We can see above that an invalid document returns non-zero
# Now we'll parse the same document but with valid syntax:
$ xmllint --noout --xinclude ./Virtual-Disk-Operations.xml
$ echo $?
0
<?xml version="1.0" encoding="utf-8"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="invalid-syntax-example"
xmlns:xl="http://www.w3.org/1999/xlink" version="5.0">
<info>
<title>Test for Developer Blog</title>
<subtitle>From the basics to the advanced</subtitle>
<foo>
<!-- The following element has no closing element, this is invalid XML -->
<bar>
</foo>
<!-- more of your stuff goes here... -->
</info>
</book>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment