Per Bernhardsson wrote:
I have finally managed to find the time to answer you. :)
This doesn't work for me for a very simple reason; the EntityResolver is
never called.
To explain a bit better:
I would like to validate the following XML stream:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<intelem>1</intelem>
<stringelem>string</stringelem>
</root>
using the following schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="intelem" type="xs:int"/>
<xs:element name="stringelem" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
As you can see there is no reference in the XML to the XSD, neither do I
want there to be a reference anywhere as the source of XML stream is
completely untrusted.
Is what I'm looking for even possible to do with Xerces?
Yes; preload the schema using loadGrammar(.., true) to have it cached,
set the "use cached grammars" flag, set validation to "always" and your
XML will be validated
Alberto
/ Per
2008/2/25, Alberto Massari <[EMAIL PROTECTED]>:
Per Bernhardsson wrote:
I'm trying to parse and validate an XML stream using an in memory copy
of a
schema. As I can't trust the source of the XML stream I need to force
validation to the correct schema. It's not acceptable solution to create
a
file containing the schema. Is it all possible?
Register an entity resolver handler to intercept the "load schema"
request, and provide a MemBufInputSource with your buffer. See the
Redirect sample for an example on how to do it.
Alberto