Hello,

I'd like to use a validating SAX parser to read huge XML documents (>200mo). 
Due to some legacy reasons, some of these files might not declare anything
related to schema or namespaces.

They look like this :

<items>
  <product id="1">...
  <product id="2">..
</items>

While the correct form would be :

<pre:itemsxmlns:pre="http://xml.prediggo.com/schema/ItemsSchema";>
  <product id="1">...
  <product id="2">..
</pre:items>


Is there anything I can do to "cheat" the schema declaration on the document
root element so that I can benefit from schema validation anyway? Writing
all the validation stuff myself would be many days of work.

I tried the following :

QName qName = new QName("http://xml.prediggo.com/schema/ItemsSchema";, "root"
);

       
xmlReader.setFeature("http://apache.org/xml/features/validation/schema"; ,
true);
       
xmlReader.setProperty("http://apache.org/xml/properties/validation/schema/root-type-definition";,
qName );


But it didn't help, I don't know if it's possible to solve the issue using
configuration and how I should do that. I consider adding the ns declaration
in the xml file using java code but it would require a complete rewrite of
the file which is rather big.

When we were still using jaxb I could *cheat* the validator by using a Sax
filter like this one. 

@Override
        public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException
        {

             if( localName.equals( "items" ))
             {
                 //inject namespace uri...
                 super.startElement(
"http://xml.prediggo.com/schema/ItemsSchema"; , localName, qName,
attributes);
             }
             else
             {
                 //do things normally...
                 super.startElement( uri , localName, qName, attributes);
             }

        }

But now, validation exceptions are thrown before my filter is even called.

Any advice would be greatly appreciated....

-- 
View this message in context: 
http://old.nabble.com/Parsing-and-validating-an-XML-Document-that-obeys-a-schema-but-doesn%27t-declare-it.-tp27942668p27942668.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to