wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Generating Valid XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Generating Valid XML" Watch "Generating Valid XML" New topic

Generating Valid XML

Edward Morris

Joined: Jun 29, 2006
Posts: 18
How do I generate XML output that conforms to a Schema? I use the DOM architecture and the DocumentBuilderFactory stuff to easily generate XML, but its just not exactly what I expect it to be i.e. its not valid. How do you assign a schema for an XML document and how do we get this schema info added to the root element of the doc. Right now I do it by using setAttribute() method but I know its not right. Any help appreciated.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Actually that probably IS right. Or at least, it's as right as you can get with DOM. The DOM API was designed before XML Schema even existed, and it doesn't do many other things well either.

That's assuming your question was how to get the schema declaration into the XML document that you are producing from the DOM. Whether the document actually conforms to the schema is a matter for unit testing.
subject: Generating Valid XML
Similar Threads
XML to Object(s)
Enable auto JAXB bindings OR do JAXB manually
generating xml from schema
how to find schema of an xml from dom program at run time
xsd compilation problem