Re: [xml] xml:base missing on result from XInclude?



On Tue, Apr 22, 2014 at 10:11:46AM +0000, Susanne Oberhauser-Hirschoff wrote:
Hi Daniel, Alexey,

Alexey Neyman <stilor att net> writes:

I think I know what is causing the issue. The code in
xmlXIncludeLoadDoc looks at the url argument to see if it is relative
path - to do so, it looks for slashes in the path. The problem is that
xmlXIncludeLoadNode() passes down URIs that are relative to the top-
level document, not to the most recent inclusion. Therefore, in the
example below the url in xmlXIncludeLoadDoc() is just '3.xml', not
'../3.xml' - and thus, the code wrongly considers it to be based in
the same directory as the current included file.

Thanks for fixing this.  Maybe this whole "check for a slash to tell if
xml:base fixup is needed" logic is flawed, though?


I'm using libxml2 2.9.1 and lxml 3.2.1

Given these example files (similar to your examples, Alexey), I get no
xml:base fixup at all:

### sample files ##################################################
# generate three example files
mkdir test
cd test
cat >1.xml <<EOF
<?xml version="1.0"?>
<top xmlns:xi="http://www.w3.org/2001/XInclude";>
  <xi:include href="2.xml"/>
</top>
EOF
cat >2.xml <<EOF
<?xml version="1.0"?>
<elem1 xmlns:xi="http://www.w3.org/2001/XInclude";>
  <xi:include href="3.xml"/>
</elem1>
EOF
cat >3.xml <<EOF
<?xml version="1.0"?>
<elem2>
  <a fileref="x.svg"/>
</elem2>
EOF
### wrong output ##################################################
# expect xml:base fixup.  Get none :(
xmllint --xinclude 1.xml 
<?xml version="1.0"?>
<top xmlns:xi="http://www.w3.org/2001/XInclude";>
  <elem1 xmlns:xi="http://www.w3.org/2001/XInclude";>
  <elem2>
  <a fileref="x.svg"/>
</elem2>
</elem1>
</top>
###################################################################


The xml:base is not just the directory, it also contains the file name,
right? 

  right but it is not needed, in that case all your files are in the
same directory, no need to add an xml:base it doesn't change any further
URI-Reference done from the included portion

The whole XInclude test suite behaves like that, see below.

  http://www.w3.org/TR/xinclude/#base

the goal was really to make sure any further URI-Reference would not
be broken.

So it _should_ look like this, shouldn't it?  This is what I get with
the attached patch to libxml:

### correct output ################################################
xmllint --xinclude 1.xml 
<?xml version="1.0"?>
<top xmlns:xi="http://www.w3.org/2001/XInclude";>
  <elem1 xmlns:xi="http://www.w3.org/2001/XInclude"; xml:base="2.xml">
  <elem2 xml:base="3.xml">
  <a fileref="x.svg"/>
</elem2>
</elem1>
</top>
###################################################################

  and with or without the xml:base the fileref URI reference will work
correctly. on the other hand having tons of xml:base getting in the
final document is more a nuisance than a benefit, especially if you
have a lot of top level XIncluded element



The XInclude test suite agrees, when run with the attached script, like
this.

###################################################################
cvs -d:pserver:anonymous dev w3 org:/sources/public \
   co  2001/XInclude-Test-Suite  XInclude-Test-Suite

cd XInclude-Test-Suite

python3 PATH-TO/run-tests-with-lxml.py
###################################################################

This gets about 15 less failures when run with the patch below, and
afaict from a review with/without patch, there is no additional ones.

So it should be an improvement :)


  Not completely sure TBH, your test suite output will look nice, the users
document not so ... which one is most important ?

Daniel


-- 
Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]