Xinclude and XPointer.. How to ? Please help me

Questions about XML that are not covered by the other forums should go here.
manuel.dorne
Posts: 9
Joined: Thu Oct 19, 2006 5:31 pm

Xinclude and XPointer.. How to ? Please help me

Post by manuel.dorne »

Hello,

I've made a xinclude call like that:

<xs:appinfo>
<Actions>
<xi:include href="testXI.xml" xpointer="A1"/>
</Actions>
</xs:appinfo>

and here is the file where i have my information:

<Noms>
<Nom Init="DF" xml:id="A1" ><LastName>Faveur</LastName><FirstName>David</FirstName></Nom>
<Nom Init="MD"><LastName>Dorne</LastName><FirstName>Manuel</FirstName></Nom>
<Nom Init="PR"><LastName>Rajaud</LastName><FirstName>Patrick</FirstName></Nom>
</Noms>

I don't know how to get the firstname of the element id="A1" via my xpointer ?

Could you help me ?

Thanks
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

oXygen offers XInclude support through Xerces which does not support the entire xpointer() scheme. However you can include only the FirstName subelement that you want using the element() scheme:

Code: Select all

<xi:include href="testXI.xml" xpointer="element(/1/1/2)" xmlns:xi="http://www.w3.org/2001/XInclude"/>
Also oXygen adds support for including an XPointer fragment through the xml:id attribute as in your case:

Code: Select all

 <Nom Init="DF" xml:id="A1" >
but the element

Code: Select all

<xi:include href="testXI.xml" xpointer="A1" xmlns:xi="http://www.w3.org/2001/XInclude"/>
includes the entire element Nom.


Regards,
Sorin
manuel.dorne
Posts: 9
Joined: Thu Oct 19, 2006 5:31 pm

Post by manuel.dorne »

Thanks for your quick answer !
manuel.dorne
Posts: 9
Joined: Thu Oct 19, 2006 5:31 pm

Post by manuel.dorne »

Hi again !

When i generate the result file, i get this

<Text>
Voici les noms des personnes de la société
<Noms xml:base="testXi.xml">
<Nom Init="DF"><LastName>Faveur</LastName><FirstName>David</FirstName></Nom>
<Nom Init="MD"><LastName>Dorne</LastName><FirstName>Manuel</FirstName></Nom>
<Nom Init="PR"><LastName>Rajaud</LastName><FirstName>Patrick</FirstName></Nom>
</Noms>
</Text>

But, this file is not valid with my XSD because of the xml:base="textXi.xml" !
Do you know how to remove residual element like xml:base on my final generated file ?

Thanks
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

manuel.dorne wrote:Do you know how to remove residual element like xml:base on my final generated file ?
You can avoid generating the xml:base attribute by disabling the Base URI fix-up option in Options -> Preferences -> XML -> XML Parser but generally this is not recommended. Why don't you modify your XSD to allow the xml:base attribute ?


Regards,
Sorin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

manuel.dorne wrote:When i generate the result file, i get this

<Text>
Voici les noms des personnes de la société
<Noms xml:base="testXi.xml">
<Nom Init="DF"><LastName>Faveur</LastName><FirstName>David</FirstName></Nom>
<Nom Init="MD"><LastName>Dorne</LastName><FirstName>Manuel</FirstName></Nom>
<Nom Init="PR"><LastName>Rajaud</LastName><FirstName>Patrick</FirstName></Nom>
</Noms>
</Text>
Use the XPointer expression which I specified to obtain only the FirstName element that you want. With the following XInclude element

Code: Select all

<xs:appinfo>
<Actions>
<xi:include href="testXI.xml" xpointer="element(/1/1/2)" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</Actions>
</xs:appinfo>
you get

Code: Select all

<xs:appinfo>
<Actions>
<FirstName xml:base="test2.xml">David</FirstName>
</Actions>
</xs:appinfo>

Regards,
Sorin
Post Reply