This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: file path peculiarity with xinclude


On Fri, Jan 17, 2003 at 04:07:39PM -0000, Lisa Carey wrote:
> Hi Bob,
> 
> No, I'm xincluding the documents that themselves incorporate additional
> material using system entities. Sorry if it wasn't clear.
> 
> They're xincluded as follows in the master document:
> 
> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
> href="mydocument1.xml"/>
> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude";
> href="mydocument2.xml"/>
> 
> where mydocument1 and mydocument2 both use system entities.  The system
> entities are all pulled in properly if I generate separate HTML docs from
> mydocument1 and mydocument2. However, only the system entities that are
> declared directly in mydocument1 and mydocument2 are found if I try to
> resolve the xincludes in the master document.  The entities that are
> declared in a separate entities file and used by both documents can't be
> found.
> 
> I can work around this, I'm just puzzled!

OK, now I think I understand what is going on.
It doesn't have anything to do with Xinclude per se,
because I can duplicate this behavior using only
system entity references.

The relevant section in the XML specification (4.2.2
External Entities) says:

"... relative URIs are relative to the location of the resource
within which the entity declaration occurs."

In this case, your document header says:

<!ENTITY % myents SYSTEM "../../common/foobarents.ent">
%myents;

And foobarents.ent contains:

<!ENTITY foo SYSTEM "../../common/foo.xml">

When the XML parser see &foo; it takes the latter reference as
relative to the location of the former reference where
the foo entity is declared,
so you get a total path of:

../../common/../../common/foo.xml

which resolves to:

../../../common/foo.xml

The solution is to use this in foobarents.ent:

<!ENTITY foo SYSTEM "foo.xml">

(if foo.xml is in the same directory as foobarents.ent).


What I don't understand is where you said your paths worked
for individual documents.  This arrangement fails for me:

Individual document:

<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "docbook42/docbookx.dtd" [
<!ENTITY % myents SYSTEM "../../common/foobarents.ent">
%myents;
]>
<book><title>foo</title>
&foo;
</book>


And ../../common/foobarents.ent contains:

<!ENTITY foo SYSTEM "../../common/foo.xml">

and foo.xml is located in ../../common.
I get the same error about not being able to load
../../../foo.xml when I process this individual
document.  I get a similar error with both
xsltproc and Saxon.

If you run xmllint --debug on the individual document,
it will show these lines:

    ENTITY_REF(foo)
      EXTERNAL_GENERAL_PARSED_ENTITY foo
      SystemID=../../common/foo.xml
      URI=../../../common/foo.xml

This shows now it converts the SystemID it finds
in foobarents.ent to a URI that is relative
to the location of foobarents.ent.

So I'm curious about
what kind of references you put in your individual
documents that got it to work with this arrangement?


Bob Stayton                                 400 Encinal Street
Publications Architect                      Santa Cruz, CA  95060
Technical Publications                      voice: (831) 427-7796
The SCO Group                               fax:   (831) 429-1887
                                            email: bobs@sco.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]