Pages

Friday, April 19, 2013

Parse and validate XML offline with XML Catalogs

When working with XML, you often see references to external files or entities, either parsed or unparsed. According to the XML Catalogues committee specification (http://www.oasis-open.org/committees/download.php/14810/xml-catalogs.pdf), XML Catalogs provide an “interoperable way to map the information in an XML external identifier into a URI reference for the desired resource.”

Most XML applications allow you to create a catalog file to resolve references to external resources. A catalog provides your application with a list of formal system identifiers to be used for validation against a DTD or schema.

Let’s say your XML file contains a reference to a Schema located on your company’s web server, like so:
<?xml version="1.0"?>
<!DOCTYPE myxml PUBLIC "-//My Company//DTD My Schema//EN"
   "http://www.mycompany.com/schema/myschema.xsd">


To parse and validate the content of this XML, the Schema needs to be available to the application. Well, if you’re working offline, this can be a problem. Luckily, you can use an XML Catalog to address this problem.

An XML Catalog entry for the above XML file might look something like this:
<catalog>
   <public publicId="-//My Company//DTD My Schema//EN"
      uri="file:///C:/xml/schema/myschema.xsd"/>.
</catalog>


Your application can use this catalog file to resolve references to external resources. In this case, your application will validate your XML file against the locally saved copy of myschema.xsd. The DTD or schema may exist on a remote server, but validation must occur regardless of whether the user is locally disconnected.

You can find more information about XML Catalogs at the http://www.oasis-open.org website.



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.