Recursive XInclusion with XPointer fragment selection

Questions about XML that are not covered by the other forums should go here.
tatra603
Posts: 76
Joined: Fri Sep 17, 2004 10:53 am
Location: Prague, the Czech Republic, Europe

Recursive XInclusion with XPointer fragment selection

Post by tatra603 »

Hello!

I have three XML files: "a.xml", "b.xml" and "c.xml". Full XML files are at the end of this message.
1) "c.xml" is simple XML file.
2) "b.xml" does simple XInclusion of "c.xml" as '<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="c.xml" parse="xml" />'.
3) "a.xml" does XInclusion of "b.xml" using XPointer as '<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="b.xml" xpointer="element(/1/1)" parse="xml" />'.

I want to have "a.xml", which contains part of "b.xml" and whole "c.xml". I am not able to do this. I receive "a.xml" containing part of "b.xml" with just reference to "c.xml" (there is not done XInclusion of "c.xml") – unparsed "b.xml". I can receive "a.xml" with (whole) "b.xml" and "c.xml", but only if I do not use XPointer. What am I doing wrong? I am using JAXP in Java 1.5.0_xx. Can You help me?

Also I did not find how to see result of XInclusion (of e.g. above "a.xml") in oXygen 7.0. Some kind of "Preview". Has oXygen such feature?

Thank You for answers. Stepan

"c.xml":
<?xml version="1.0" encoding="UTF-8"?>
<c xmlns:xi="http://www.w3.org/2001/XInclude">
<element>
<text>ccc</text>
</element>
</c>

"b.xml":
<?xml version="1.0" encoding="UTF-8"?>
<b xmlns:xi="http://www.w3.org/2001/XInclude">
<element>
<text>bbb</text>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="c.xml" parse="xml"/>
</element>
</b>

"a.xml":
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xi="http://www.w3.org/2001/XInclude">
<element>
<text>aaa</text>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="b.xml" xpointer="element(/1/1)" parse="xml" />
</element>
</a>

part of my simple Java 1.5.0_xx code:
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setXIncludeAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new File("a.xml"));
tatra603
Posts: 76
Joined: Fri Sep 17, 2004 10:53 am
Location: Prague, the Czech Republic, Europe

Post by tatra603 »

Well, I can partially answer my previous questions ;-)

How to preview final XML file after XInclusion? I wrote simple XSLT, which copy all elements and attributes from source to output. Hmm, but maybe it can be done by easier way.

Recursive XInclusion using XPointer is OK in oXygen using Xalan or Saxon8B. So it looks like I have some kind of error in my Java code, but I do not know where, because it is too simple to have any error there :-( I am going to install JAXP plugin to oXygen to test JAXP XInclusion within oXygen.

Stepan
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Stepan,

Yes, in order to see the document with the XInclude resolved you can pass it through a simple stylesheet like:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
The XInclude does not invlolve the XSLT processor, the XInclude is resolved at XML parser level, in oXygen that is Xerces. If you create the parser through JAXP in Java 1.5 then you probably get a modified Xerces version bundled with Java as com.sun.org.apache.xerces... etc. and I do not know what XInclude support that offers. The JAXP option in oXygen is under XSLT options and refers to configuring oXygen to work with a Java XSLT processor that is not already integrated in oXygen by specifying the factory class for that processor so that will not help you with XInclude testing. Maybe you should better configure JAXP to create a Xerces parser instead of the default parser, that should give you something similar with what oXygen does.

Best Regards,
George
Post Reply