XInclusion: fragment defined by ID?

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

XInclusion: fragment defined by ID?

Post by tatra603 »

Hello!

I want to do fragment XInclusion. Something like [url]http://www.w3.org/TR/xinclude/#fragment-example[/url] I have element "table" defined with ID according to [url]http://www.zvon.org/xxl/XPointerTutoria ... d_st0.html[/url] using XSD as:

<xs:element name="table">
<xs:complexType mixed="false">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" ref="column"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="table"/>
</xs:sequence>
<xs:attribute name="xmlName" use="required" type="xs:NCName"/>
<xs:attribute name="sql" use="required"/>
<xs:attribute ref="xml:base" use="optional"/>
<xs:attribute name="id" type="xs:ID" use="optional"/>
</xs:complexType>
</xs:element>

But when I want to use <xi:include href="test.xml" xpointer="element(bdp)"/>, there is an error "XPointer resolution unsuccessfull". When I use <xi:include href="test.xml" xpointer="element(/1)"/> (first element of document tree), all is OK.

So, please, where is the problem? Does oXygen (JAXP) support XPointer expression based on ID? Or is the problem on my side (I hope it is). Thank You, Stepan.

My test.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<table id="bdp" xmlName="bdp" sql="select * from testTable">
<column xmlName="kod" sqlName="kod"/>
</table>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hello,

Xerces 2.7.1 has a limited support for IDs for XML inclusion to only DTD determined IDs [1]. We applied a patch in oXygen 7 to support also IDs that are defined with xml:id no matter if a schema or a DTD is specified or not. You can find below a full working sample.

test.xsd - note that this is not required for XInclude to work, I added only if you want to see how the corresponding schema will look like.

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2005/08/xml.xsd"/>
<xs:element name="table">
<xs:complexType mixed="false">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="table"/>
</xs:sequence>
<xs:attribute ref="xml:base" use="optional"/>
<xs:attribute ref="xml:id" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
text.xml

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<table xml:id="t1">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="testInc.xml" xpointer="tInc"/>
</table>
textInc.xml

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<table xml:id="t2">
<table xml:id="tInc">
</table>
</table>
test.xsl

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>
resut

Code: Select all


<?xml version="1.0" encoding="UTF-8"?><table xml:id="t1">
<table xml:id="tInc" xml:base="testInc.xml">
</table>
</table>
[1] http://xerces.apache.org/xerces2-j/faq- ... html#faq-8 look for What types of IDs are currently supported for XPointers?

Best Regards,
George
Post Reply