Java, validate XML with XSD, XML not containing "xmlns:xsi=..."

K

killy971

I am using java to validate an XML file with a DTD, without having the
DVD declaration inside the original file, by setting the doctype
dynamically to a transformer like this :

transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtd);
transformer.transform(source, new StreamResult(new
StringWriter()));

I would like to know if there is a way to validate an XML file with an
XSD, again, without having the declaration of the xsd file inside the
original XML file, but by declaring it dynamically.

Thank you !
 
J

Johannes Koch

killy971 said:
I am using java to validate an XML file with a DTD, without having the
DVD declaration inside the original file, by setting the doctype
dynamically to a transformer like this :

transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtd);
transformer.transform(source, new StreamResult(new
StringWriter()));

DTD validation is tightly connected to parsing. So you can parse the
result of the transformation with a validating parser.
I would like to know if there is a way to validate an XML file with an
XSD, again, without having the declaration of the xsd file inside the
original XML file, but by declaring it dynamically.

Have a look at "Chapter 14. Package javax.xml.validation" of "JSR 206
Java™ API for XML Processing (JAXP) 1.3".
 
J

Johannes Koch

Johannes said:
DTD validation is tightly connected to parsing. So you can parse the
result of the transformation with a validating parser.


Have a look at "Chapter 14. Package javax.xml.validation" of "JSR 206
Java™ API for XML Processing (JAXP) 1.3".

In this case I'd transform into a DOMResult and then pass the resulting
node to the schema validation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top