You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Dick Deneer <di...@donkeydevelopment.com> on 2006/10/14 13:26:38 UTC

How to access XMLResourceIdentifier from LSResourceResolver

Hi,

I am using the DOM level 3 api to create a DOM using :

         DOMImplementationRegistry registry =
                 DOMImplementationRegistry.newInstance();
         DOMImplementationLS domImpl = (DOMImplementationLS)
                 registry.getDOMImplementation("LS 3.0");

         LSParser parser = domImpl
                 .createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
                                 XMLConstants.W3C_XML_SCHEMA_NS_URI);

       org.w3c.dom.DOMConfiguration config = parser.getDomConfig();
       config.setParameter("resource-resolver", resolver);  //where  
resolver is an LSResolver

         Document doc = parser.parseURI(sourceURI);

Afterwards I am using the DOM Validation api to validate the DOM when  
it is modified.


The LSResolver  has the resolveResoure method:

public LSInput resolveResource(String type, String namespaceURI,
			String publicId, String systemId, String baseURI)

My problem is that I need much more information about the resource  
than what is passed to this method.
For instance I can not distinguish a DTD grammar from an  
XMLEntityDescription because from the "type" parameter passed.
 From the debugger I saw that one level higher in the stack the  
DOMEntityResolverWrapper has all the information I need in the  
XMLResourceIdentifier interface object.
Is there anyway to get acces to this.

By the way, at the "sax-side" of my program I do not have this issue,  
by using the   XMLEntityResolver() with has this method:
				
public XMLInputSource resolveEntity(XMLResourceIdentifier arg0)  
throws XNIException, IOException)


Dick Deneer




Re: How to access XMLResourceIdentifier from LSResourceResolver

Posted by Dick Deneer <di...@donkeydevelopment.com>.
Just tested the your suggestion of ExternalSubsetResolver.
Thanks, this works great!


Op 16-okt-2006, om 23:50 heeft Michael Glavassevich het volgende  
geschreven:

> Dick Deneer <di...@donkeydevelopment.com> wrote on 10/16/2006
> 05:20:47 PM:
>
>> As you have probably seen, I created XERCESJ-1204 for this issue.
>
> Thanks.
>
>> Maybe you can take the opportunity to create something like a
>> XMLEntityResolver2, which also has an getExternalSubset method.
>> In fact EntityResolver2Wrapper has it all.
>
> Something like that already exists though it isn't part of XNI. Take a
> look at ExternalSubsetResolver [1]. If your XMLEntityResolver  
> implements
> this interface the parser will call its getExternalSubset() method  
> if the
> document doesn't have an external subset.
>
>> This way it also would become possible to use the XMLEntityResolver
>> when validating against an external (user assigned) DTD if there is
>> nothing declared in the xml instance. In the getExternalSubset we
>> could then return the external DTD.
>> Now when using XMLEntityResolver in the saxParser there is no other
>> way than actually insert the doctype in the source, because the
>> properties "http://apache.org/xml/properties/schema/external-
>> schemaLocation" or  "http://apache.org/xml/properties/schema/ 
>> external-
>> noNamespaceSchemaLocation" do not have affect when validating against
>> a DTD.
>> In the DomConfiguration this is no problem because
>> DOMConfiguration.setParameter("schema-location", schema) works for
>> both XMLSchema and DTD.
>
> [1]
> http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/ 
> xerces/impl/ExternalSubsetResolver.html
>
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>


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


Re: How to access XMLResourceIdentifier from LSResourceResolver

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Dick Deneer <di...@donkeydevelopment.com> wrote on 10/16/2006 
05:20:47 PM:

> As you have probably seen, I created XERCESJ-1204 for this issue.

Thanks.

> Maybe you can take the opportunity to create something like a 
> XMLEntityResolver2, which also has an getExternalSubset method.
> In fact EntityResolver2Wrapper has it all.

Something like that already exists though it isn't part of XNI. Take a 
look at ExternalSubsetResolver [1]. If your XMLEntityResolver implements 
this interface the parser will call its getExternalSubset() method if the 
document doesn't have an external subset.

> This way it also would become possible to use the XMLEntityResolver 
> when validating against an external (user assigned) DTD if there is 
> nothing declared in the xml instance. In the getExternalSubset we 
> could then return the external DTD.
> Now when using XMLEntityResolver in the saxParser there is no other 
> way than actually insert the doctype in the source, because the 
> properties "http://apache.org/xml/properties/schema/external- 
> schemaLocation" or  "http://apache.org/xml/properties/schema/external- 
> noNamespaceSchemaLocation" do not have affect when validating against 
> a DTD.
> In the DomConfiguration this is no problem because 
> DOMConfiguration.setParameter("schema-location", schema) works for 
> both XMLSchema and DTD.

[1] 
http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/xerces/impl/ExternalSubsetResolver.html


Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

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


Re: How to access XMLResourceIdentifier from LSResourceResolver

Posted by Dick Deneer <di...@donkeydevelopment.com>.
As you have probably seen, I created XERCESJ-1204 for this issue.

Maybe you can take the opportunity to create something like a  
XMLEntityResolver2, which also has an getExternalSubset method.
In fact EntityResolver2Wrapper has it all.

This way it also would become possible to use the XMLEntityResolver  
when validating against an external (user assigned) DTD if there is  
nothing declared in the xml instance. In the getExternalSubset we  
could then return the external DTD.
Now when using XMLEntityResolver in the saxParser there is no other  
way than actually insert the doctype in the source, because the  
properties "http://apache.org/xml/properties/schema/external- 
schemaLocation" or  "http://apache.org/xml/properties/schema/external- 
noNamespaceSchemaLocation" do not have affect when validating against  
a DTD.
In the DomConfiguration this is no problem because  
DOMConfiguration.setParameter("schema-location", schema) works for  
both XMLSchema and DTD.




Op 16-okt-2006, om 19:22 heeft Michael Glavassevich het volgende  
geschreven:

> I was going to suggest that you set the "
> http://apache.org/xml/properties/internal/entity-resolver" property  
> on the
> DOMConfiguration but just noticed that isn't possible. It will  
> throw an
> exception without first attempting to set the property on the internal
> XMLParserConfiguration. Could you please open a JIRA issue?
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Dick Deneer <di...@donkeydevelopment.com> wrote on 10/14/2006
> 07:26:38 AM:
>
>> Hi,
>>
>> I am using the DOM level 3 api to create a DOM using :
>>
>>         DOMImplementationRegistry registry =
>>                 DOMImplementationRegistry.newInstance();
>>         DOMImplementationLS domImpl = (DOMImplementationLS)
>>                 registry.getDOMImplementation("LS 3.0");
>>
>>         LSParser parser = domImpl
>>                 .createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
>>                                 XMLConstants.W3C_XML_SCHEMA_NS_URI);
>>
>>       org.w3c.dom.DOMConfiguration config = parser.getDomConfig();
>>       config.setParameter("resource-resolver", resolver);  //where
>> resolver is an LSResolver
>>
>>         Document doc = parser.parseURI(sourceURI);
>>
>> Afterwards I am using the DOM Validation api to validate the DOM
>> when it is modified.
>>
>> The LSResolver  has the resolveResoure method:
>>
>> public LSInput resolveResource(String type, String namespaceURI,
>> String publicId, String systemId, String baseURI)
>>
>> My problem is that I need much more information about the resource
>> than what is passed to this method.
>> For instance I can not distinguish a DTD grammar from an
>> XMLEntityDescription because from the "type" parameter passed.
>> From the debugger I saw that one level higher in the stack the
>> DOMEntityResolverWrapper has all the information I need in
>> the XMLResourceIdentifier interface object.
>> Is there anyway to get acces to this.
>>
>> By the way, at the "sax-side" of my program I do not have this
>> issue, by using the   XMLEntityResolver() with has this method:
>> public XMLInputSource resolveEntity(XMLResourceIdentifier
>> arg0) throws XNIException, IOException)
>>
>> Dick Deneer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>


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


Re: How to access XMLResourceIdentifier from LSResourceResolver

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
I was going to suggest that you set the "
http://apache.org/xml/properties/internal/entity-resolver" property on the 
DOMConfiguration but just noticed that isn't possible. It will throw an 
exception without first attempting to set the property on the internal 
XMLParserConfiguration. Could you please open a JIRA issue?

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Dick Deneer <di...@donkeydevelopment.com> wrote on 10/14/2006 
07:26:38 AM:

> Hi,
> 
> I am using the DOM level 3 api to create a DOM using :
> 
>         DOMImplementationRegistry registry =
>                 DOMImplementationRegistry.newInstance();
>         DOMImplementationLS domImpl = (DOMImplementationLS)
>                 registry.getDOMImplementation("LS 3.0");
> 
>         LSParser parser = domImpl
>                 .createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
>                                 XMLConstants.W3C_XML_SCHEMA_NS_URI);
> 
>       org.w3c.dom.DOMConfiguration config = parser.getDomConfig();
>       config.setParameter("resource-resolver", resolver);  //where 
> resolver is an LSResolver
> 
>         Document doc = parser.parseURI(sourceURI);
> 
> Afterwards I am using the DOM Validation api to validate the DOM 
> when it is modified.
> 
> The LSResolver  has the resolveResoure method:
> 
> public LSInput resolveResource(String type, String namespaceURI,
> String publicId, String systemId, String baseURI)
> 
> My problem is that I need much more information about the resource 
> than what is passed to this method.
> For instance I can not distinguish a DTD grammar from an 
> XMLEntityDescription because from the "type" parameter passed.
> From the debugger I saw that one level higher in the stack the 
> DOMEntityResolverWrapper has all the information I need in 
> the XMLResourceIdentifier interface object.
> Is there anyway to get acces to this.
> 
> By the way, at the "sax-side" of my program I do not have this 
> issue, by using the   XMLEntityResolver() with has this method:
> public XMLInputSource resolveEntity(XMLResourceIdentifier 
> arg0) throws XNIException, IOException)
> 
> Dick Deneer

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