1

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>
1
  • 1
    Xerces java or c++? Also, what do you mean by "inline schema"? Show us an example. Commented Jan 20, 2011 at 14:02

2 Answers 2

1

It turns out that it supports inline schemas: http://xerces.apache.org/xerces2-j/samples-jaxp.html#InlineSchemaValidator

Sign up to request clarification or add additional context in comments.

Comments

0

You might want to read the file in as regular xml file, us an xpath expression to select to the schema element, and then transfrom that into an input stream. Then call the parser on that input stream.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.