Created
December 6, 2013 18:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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