You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Taras Tielkes <ta...@info.nl> on 2001/11/14 15:45:32 UTC
Schema validation of a DOM Document instance
Hi,
I have an instance of Document in memory. I know Xerces 1.x cannot directly
validate a DOM.
Is it possible to generate a stream of SAX events from the DOM, and somehow
validate *that* against a Schema?
For instance, the DOM2SAX class in the Xalan jar will translate a DOM into
SAX events, but as far as I see there is no way to include Schema
validation in that process.
Thanks in advance for any suggestions,
// tt
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
RE: Schema validation of a DOM Document instance
Posted by Doug Helton <dh...@ideorlando.org>.
Hi Taras,
Even though the DOM is in memory you can stil validate it. At least you
can if you are using xerces 1.4.3.
It is a round about way but it still works.
you can serialize the DOM then create a inputSource to pass to the parser
after setting the parser to validate against the schema.
parser.setFeature("http://xml.org/sax/features/validation",
true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che
cking", true);
parser.setFeature("http://apache.org/xml/features/validation/warn-on-duplica
te-attdef",true);
parser.setFeature("http://apache.org/xml/features/validation/warn-on-undecla
red-elemdef",true);
Here is an example:
// The below code converts the DOcument Object to a String
StringReader strReader = null;
OutputFormat outputFormat = new OutputFormat();
StringWriter stringOut = new StringWriter();
XMLSerializer serial = null;
this.errorCount = 0;
outputFormat.setIndenting(true);
outputFormat.setOmitComments(false);
outputFormat.setOmitDocumentType(false);
outputFormat.setOmitXMLDeclaration(false);
outputFormat.setEncoding("US-ASCII");
serial = new XMLSerializer(stringOut, outputFormat);
serial.asDOMSerializer();
serial.serialize(doc);
strReader = new StringReader(stringOut.toString());
InputSource source = new InputSource(strReader)
parser.parse(source);
-----Original Message-----
From: Taras Tielkes [mailto:taras@info.nl]
Sent: Wednesday, November 14, 2001 9:46 AM
To: Xerces-J-User (E-mail)
Subject: Schema validation of a DOM Document instance
Hi,
I have an instance of Document in memory. I know Xerces 1.x cannot directly
validate a DOM.
Is it possible to generate a stream of SAX events from the DOM, and somehow
validate *that* against a Schema?
For instance, the DOM2SAX class in the Xalan jar will translate a DOM into
SAX events, but as far as I see there is no way to include Schema
validation in that process.
Thanks in advance for any suggestions,
// tt
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org