Skip to main content

How to handle mixed DTD/Schema

3 replies [Last post]
mkuppe
Offline
Joined: 2006-02-16

I am building an application that uses a set of java classes generated using xjc from an XSD. The problem is that the application needs to communicate with another system which is using a DTD instead of a XSD.
Some example xml documents provided by the developers of the other system shows a DOCTYPE with a reference to thier DTD.
I am interested in knowing whether this setup will work, when marshalling and unmarshalling the resulting XML documents. Ideally I am interested in reproducing the xml from the example xml documents, including the DOCTYPE reference.
I can see two problems, first that i do not produce the DOCTYPE reference when i marshal the object and I am not sure how the unmarshaller will handle the DOCTYPE reference when unmarshalling.
I would appreciate any guidance in how this could best be handled.

thanks in advance...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

You can unmarshal a document that includes DOCTYPE just fine. If you need to ignore the declaration (for example if the system/public ID doesn't resolve when you read it), you can do so but you need to configure a parser. For example, Xerces lets you do that through properties.

To marshal an XML with a DOCTYPE declaration, see https://jaxb.dev.java.net/jaxb20-ea3/docs/vendorProperties.html#xmldecl

mkuppe
Offline
Joined: 2006-02-16

For the unmarshalling, I assume that i could also just provide the DTD so that the unmarshallers default sax parser will find it... how would i do this? the DOCTYPE element looks like this:

How could i make the xxxxx.dtd available to the parser?

Thanks in advance!

kohsuke
Offline
Joined: 2003-06-09

Check some JAXP/SAX resources on the web. Use EntityResolver.