I have an XML schema that was built with an old version of the XML spec (http://www.w3.org/1999/XMLSchema). I am tr开发者_开发百科ying to parse XML messages using the schema (shown below). By default, the Xerces 1.1 parser looks for the schema in the app domain root directory. I am trying to move the schema to a public location in our web directory. It seems like I cannot specify a URL as the schema location in my parsing program using the Xerces 1.1 library.
So I tried to upgrade my program to use JAXP DocumentBuilderFactory and its setSchema() method. This seems to find the schema with the schema URL I provide it, except that it gives parsing errors because the schema (presumably) does not conform to a later version of the spec (for example, I get errors because my Ticket element doesn't wrap its members inside an xs:Sequence).
I can't upgrade my schema since I can't, at this time, force external customers to rewrite their apps that send messages to us.
Can anyone tell me how to use JAXP to successfully parse/validate using an old-school version of the schema spec? Or alternatively, is there a way to tell the Xerces 1.1 DOMParser to use a schema defined by a URL (not a file location)?
Here is a sample of what the schema looks like:
<?xml version="1.0" encoding="UTF-8" ?>
<schema>
<element name="Ticket">
<complexType>
<element ref="ID" />
<element ref="User" />
</complexType>
</element>
<element name="ID" type='string' />
<element name="UserID" type='string' />
</schema>
The XML document looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Ticket xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='TicketSubmission.xsd'>
<ID>2010:December2:Dec:12:05:33:245</ID>
<UserID>user123</UserID>
</Ticket>
Thanks!
Use an old-school version of JAXP; maybe 1.6
So, I've come to the conclusion that using the 1999 schema spec is a bad idea. Earlier versions of the Xerces parser that support the 1999 schema spec don't seem to be flexible in where the schemas can reside on disk. I'm probably stuck with placing the schemas in the app server root directory until we can get our clients to use a newer version of our schema.
Later versions of Xerces (even prior to Xerces 2) seem to have abandoned support of the 1999 schema spec in favor of the 2001 schema spec. Although, later versions of Xerces seem like they allow more flexibilty in the location of the schema files.
精彩评论