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 Neeraj Bajaj <Ne...@Sun.COM> on 2002/02/28 15:16:39 UTC

Re: Urgent... Any suggestion please!!!

Hi Haladhar,

	I am forwarding this mail to two mailing lists for its wide usage.
	
>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?

I have recently commited some changes (after Xerces 2.0.0 release ) for defer 
loading of grammar, now we dont (parse) load the grammar unless there is 
reference to any schema component from that namespace. 
Say your instance file looks like these..

<root>
...
	<child1>
		<N1:child2 xmlns:N1="someuri" ...>
		</N1>
	</child1>
</root>

Now parser will load the schema grammar associated with namespace N1 only when 
it sees child2 (from namespace N1). If there is no reference from N1, it wont be 
loaded at all. Parser tries to parse the schema grammar using location hint 
available for that namespace (In your case through external-schema location 
property), while doing this parser also gives chance to application by providing 
its own EnityResolver to over-ride location hint available.
	
Please check, if the latest code in CVS works for you,  by taking the latest jar
from http://gump.covalent.net/jars/latest/xml-xerces2/. However, a bug-fix 
release of Xerces 2.0 is coming out soon and these changes would be available 
with it.

Thanks.

--
Neeraj,
SUN Microsystems, inc.


> From: hrout@pershing.com
> Subject: Urgent... Any suggestion please!!!
> To: neeraj.bajaj@sun.com
> Date: Wed, 27 Feb 2002 14:49:52 -0500
> X-MIMETrack: Serialize by Router on Pershing2/External(Release 5.0.7 |March 
21, 2001) at 02/27/2002 02:49:57 PM
> 
> Neeraj,
> 
> I am working with JAXP and XML using Xerces2. I am specifying all the
> schemas needed for my application thru the property externalSchemaLocation
> using setAttribute() method of DocumentBuilderFactory class.
> 
> As I understand, I can create multiple DocumentBuilders from the single
> DocumentBuilderFactory and all the DocumentBuilders will share the common
> properties specified in the Factory. But here is the problem I'm facing:
> 
> 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?
> 
> Here the code I am using:
> 
> // 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 and regards.
> Haladhar
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org