Hi folks,
I have a problem with Xerces2. I have put the code snippet and the problem
as follows:
Code Used:
// Create a Parser Factory Instance
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Make it validating and Schema NameSpace aware
factory.setNamespaceAware(true);
factory.setValidating(true);
// Set Schema Language name space (required for JAXP1.2, supported by
Xerces2 only)
factory.setAttribute("
http://java.sun.com/xml/jaxp/properties/schemaLanguage","
http://www.w3.org/2001/XMLSchema");
// Set external schemalocations as follows: URN URI URN URI
factory.setAttribute("
http://apache.org/xml/properties/schema/external-schemaLocation",
"urn:schema1 http://host/schemas/schema1.xsd " +
"urn:schema2 http://host/schemas/schema2.xsd "+
"urn:schema3 http://host/schemas/schema3.xsd "+
"urn:schema4 http://host/schemas/schema4.xsd");
// Create Parser
DocumentBuilder builder = factory.newDocumentBuilder();
// Set Entity Resolver, this does not really help much
builder.setEntityResolver( new Resolver() );
builder.setErrorHandler(errorHandler);
Document doc = builder.parse("c:\\test.xml");
printNode(doc, "");
System.out.println("\nFinished");
Problem:
The xml file test.xml uses 2 schemas only. When I invoke the parse method
of the builder it parses all the 4 schemas I have specified in the
setAttribute method which is not required.
My purpose is as follows:
Create a Parser Factory
Set All Schema Locations only once
Get a parser from the Parser factory and parse a message. Now ,
according to me, the parser should get only the required(means schemas
used for the specified xml message only) schema locations from the
ParserFactory property. Rather the parser uses all the schemas specified
in the ParserFactory even if those schemas are not required for the xml
message.
I went thru the source code of Xerces2. It seems that the parser parses all
the specified schemas when you invoke a parse method. Even if I use my own
EntityResolver it does not help.
Am I missing something or making any mistake somewhere?
Any suggestion to this will be of great help. thanks.
Haladhar
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]