xmllint.
To validate an XML file against:
- a DTD stored in the same file:
xmllint --valid --noout fileWithDTD.xml
xmllint --dtdvalid DTD.dtd --noout fileWithoutDTD.xml
xmllint --schema schema.xsd --noout file.xmlThe
--noout option suppresses the output of the xml file.
ExampleTo validate:
<countries>
<country name="Afghanistan" population="22664136" area="647500">
<language percentage="11">Turkic</language>
<language percentage="35">Pashtu</language>
<language percentage="50">Afghan Persian</language>
</country>
<country name="Albania" population="3249136" area="28750"/>
<country name="Algeria" population="29183032" area="2381740">
<city>
<name>Algiers</name>
<population>1507241</population>
</city>
</country>
</countries>
against:
<!ELEMENT countries (country*)> <!ELEMENT country (language|city)*> <!ATTLIST country name CDATA #REQUIRED> <!ATTLIST country population CDATA #REQUIRED> <!ATTLIST country area CDATA #REQUIRED> <!ELEMENT language (#PCDATA)> <!ATTLIST language percentage CDATA #REQUIRED> <!ELEMENT city (name, population)> <!ELEMENT name (#PCDATA)> <!ELEMENT population (#PCDATA)>use the command:
xmllint --dtdvalid countries.dtd --noout countries.xml
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.