You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by hr...@pershing.com on 2002/02/26 21:18:22 UTC

JAXP with Xerces2

Hi folks,

I'm using Xerces2 and implmenting JAXP. following is my requirement and
problem:

   Create a DOM Parser Factory ( so that I can create multiple parsers
   which will share the factory properties )
   Set all the schema locations to factory only once so that all the
   parsers created from the factory can get the schema locations at
   runtime. So that I dont have to specify the schema location to each
   parser.
        But the problem is : Suppose I specified 10 schemaLocations to the
factory. I created a parser and tried to parse an xml message which uses
only 2 of the specified schemas. The parser tries to parse all the 10
schemas instead of the only 2 required ones. Is there any way I can specify
the parser to parse and use only the required schemas but not all the
schemas?

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 " +
     "urn:schema5 http://host/schemas/schema5.xsd "+
     "urn:schema6 http://host/schemas/schema6.xsd "+
     "urn:schema7 http://host/schemas/schema7.xsd " +
     "urn:schema8 http://host/schemas/schema8.xsd "+
     "urn:schema9 http://host/schemas/schema9.xsd "+
     "urn:schema10 http://host/schemas/schema10.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 in detail:

The xml file test.xml uses 2 schemas only. When I invoke the parse method
of the builder it parses all the 10 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: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org