Difference between revisions of "XML Validation"

From Ittichai Chammavanijakul's Wiki
Jump to navigation Jump to search
Line 4: Line 4:
  
 
To validate XML data with a DTD stored in the same file:
 
To validate XML data with a DTD stored in the same file:
 
+
<pre>
 
   xmllint --valid --noout DataFileWithDTD.xml
 
   xmllint --valid --noout DataFileWithDTD.xml
 
+
</pre>
  
 
To validate XML data against a separately stored DTD:
 
To validate XML data against a separately stored DTD:

Revision as of 16:13, 16 November 2011

The xmllint tool can be used to validate XML documents against DTDs and XML Schema definitions. It can be downloaded as a part of the free, open-source libxml2 package at http://xmlsoft.org/xmldtd.html.

These are some examples of using the xmllint command.

To validate XML data with a DTD stored in the same file:

  xmllint --valid --noout DataFileWithDTD.xml

To validate XML data against a separately stored DTD:

 xmllint --dtdvalid DTD.dtd --noout DataFileWithoutDTD.xml


To validate XML data against a separately stored XML Schema definition:

 xmllint --schema XMLSchemaFile.xsd --noout DataFile.xml


Alternatively, the following online services can also be used to validate XML:

  • W3C Markup Validation Service for DTDs
  • XML for ASP.NET Schema Validator for XML Schema.