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 Simon Kitching <si...@ecnetwork.co.nz> on 2004/10/06 03:36:05 UTC

Re: Resolving relative paths for external entities

On Wed, 2004-10-06 at 14:23, Peter wrote:
>  Hi
>  
>  I have a document with an external entity:
>  
>  <?xml version="1.0"?>
>  <!DOCTYPE hibernate-mapping PUBLIC
> "-//Hibernate/Hibernate Mapping DTD//EN"
> 
> "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd";
>  [
>  <!ENTITY Contingency SYSTEM
> "components/hsos.contingency.persistence.Contingency.xml">
>  ]
>  >
>  
>  So "components/" is a sub directory in the same
> directory this document is located in. According to
> RFC 2396 the base URI for the relative path for the
> external entity should fall back to the location of
> this document. This works fine validating the doucment
> with xmllint but when using dom4j/xerces it always
> tries to use "." as the base URI. How can this
> behaviour be changed/corrected?

Hi Peter,

If you call a parse method passing a File or URI then entities *will*
get resolved relative to the source location of the document.

But if you call a parse method passing an InputSource or InputStream
object, then xerces has no idea what the original source location of the
document it is parsing *is*. I presume this is what the problem is in
your case.

When using an InputSource, you can call InputSource.setSystemId to tell
the parser what the "source location" of the input document is.

Regards,

Simon


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


Re: Resolving relative paths for external entities

Posted by Peter <th...@yahoo.com>.
Hi Simon

Thank you for your detailed and informative reply. I'm
wading my way through hibernate & dom4j to see how
xerces is used, not an easy task ;) 

Cheers!
Peter

--- Simon Kitching <si...@ecnetwork.co.nz> wrote:

> On Wed, 2004-10-06 at 14:23, Peter wrote:
> >  Hi
> >  
> >  I have a document with an external entity:
> >  
> >  <?xml version="1.0"?>
> >  <!DOCTYPE hibernate-mapping PUBLIC
> > "-//Hibernate/Hibernate Mapping DTD//EN"
> > 
> >
>
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd";
> >  [
> >  <!ENTITY Contingency SYSTEM
> >
>
"components/hsos.contingency.persistence.Contingency.xml">
> >  ]
> >  >
> >  
> >  So "components/" is a sub directory in the same
> > directory this document is located in. According
> to
> > RFC 2396 the base URI for the relative path for
> the
> > external entity should fall back to the location
> of
> > this document. This works fine validating the
> doucment
> > with xmllint but when using dom4j/xerces it always
> > tries to use "." as the base URI. How can this
> > behaviour be changed/corrected?
> 
> Hi Peter,
> 
> If you call a parse method passing a File or URI
> then entities *will*
> get resolved relative to the source location of the
> document.
> 
> But if you call a parse method passing an
> InputSource or InputStream
> object, then xerces has no idea what the original
> source location of the
> document it is parsing *is*. I presume this is what
> the problem is in
> your case.
> 
> When using an InputSource, you can call
> InputSource.setSystemId to tell
> the parser what the "source location" of the input
> document is.
> 
> Regards,
> 
> Simon
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> xerces-j-user-help@xml.apache.org
> 
> 

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