Is it possible to parse a XML file with an inline schema using Xerces? I've been trying every way I can to make this work but I couldn't succeed. It always throws an exception at the last line of the code below (schema is a string that contains the xml and the inline schema):
private XSModel getXSModel(String schema) throws XNIException, IOException{
XMLGrammarPreparser preparser = new XMLGrammarPreparser();
preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
XSGrammar g = (XSGrammar)preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,new XMLInputSource(null, null, null,new ByteArrayInputStream(schema.getBytes()), "ISO-8859-1"));
return g.toXSModel();
}
The error is as follow:
[Error] :1:9586: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'...
That message appears for each line belonging to the XML (out of schema tag)
Update: Here is an example:
<root>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="age" type="integer"/>
</schema>
<!--HERE THE XML BEGINS-->
<age>35</age>
</root>