BaseX, xinclude and xpointer

Friday, 12 February 2021 · 11 messages · last reply 19 Feb 2021
P
pascaljoubaud12 Feb 2021 19:27 #
Hello BaseX-Community, I'm a beginner with baseX so my questions may sound a bit weird. I hope not too much. I have a problem using xinclude in a baseX database. Basically i have a main file which contains this xinclude instruction :
<xi:include href="EP15.xml" xpointer="element(EP15)"><xi:fallback><p>Pièce non encodée pour le moment.</p></xi:fallback></xi:include>
In my baseX database i have my main file and the EP15.xml file which contains this instruction :
<div type="Piece" xml:id="EP15">blabla<div>
When i 'm looking to my main file in base X, i always have the fallback instruction displayed :
<p>Pièce non encodée pour le moment.</p>
I'm using baseX 9.3.2., the local option XINCLUDE is turned on. I have also tried to use direct xpath instead of a named element in my xpointer xpointer="element(/TEI/text/body/div[1])"> but the resultat is stille the same I'm a bit stuck at the moment.. Any help would be very much appreciated ! Thanks a lot Pascal
CG
Christian Grün16 Feb 2021 11:00 #
Hi Pascal, Welcome to the list, thanks for your contribution.
Quoted text · pascaljoubaud · 5 lines
> Basically i have a main file which contains this xinclude instruction : > > <xi:include href="EP15.xml" xpointer="element(EP15)"><xi:fallback><p>Pièce non encodée pour le moment.</p></xi:fallback></xi:include> > > In my baseX database i have my main file and the EP15.xml file which contains this instruction :
The XINCLUDE option affects the behavior of the default Java XML parser, which will try to look up files in your local file system. This means you may need to ensure that EP15.xml is located in the same directory as your main file when add the latter one to the database. Does this help? Salutations cordiales, Christian
P
pascaljoubaud16 Feb 2021 19:29 #
Hi Christian, Thanks for your answer. Both files are in the same local directory when loading into BaseX. I've tried several things like removing the xpointer (to make sure it's not the problem) and the fallback scenario. When I add the file into BaseX I now have the following message when adding the main file into BaseX.
Quoted text · Christian Grün · 1 line
> An include with href 'EP15.xml'failed, and no fallback element was found.
I keep trying but cannot get it to work. Thanks for your help Pascal -----Message d'origine-----
Quoted text · Christian Grün · 19 lines
De : Christian Grün <christian.gruen at gmail.com> Envoyé : mardi 16 février 2021 11:00 À : pascaljoubaud at gmail.com Cc : BaseX <basex-talk at mailman.uni-konstanz.de> Objet : Re: [basex-talk] BaseX, xinclude and xpointer Hi Pascal, Welcome to the list, thanks for your contribution. > Basically i have a main file which contains this xinclude instruction : > > <xi:include href="EP15.xml" > xpointer="element(EP15)"><xi:fallback><p>Pièce non encodée pour le > moment.</p></xi:fallback></xi:include> > > In my baseX database i have my main file and the EP15.xml file which contains this instruction : The XINCLUDE option affects the behavior of the default Java XML parser, which will try to look up files in your local file system. This means you may need to ensure that EP15.xml is located in the same directory as your main file when add the latter one to the database. Does this help? Salutations cordiales, Christian
CG
Christian Grün17 Feb 2021 10:03 #
Quoted text · pascaljoubaud · 3 lines
> When I add the file into BaseX I now have the following message when adding the main file into BaseX. > > > An include with href 'EP15.xml'failed, and no fallback element was found.
Feel free to send us/me the files in question, I can have a look at that.
CG
Christian Grün17 Feb 2021 19:17 #
Hi Pascal, Thanks for the sample files. The error you reported is returned by Java’s default XML parser (the one from Xerces), so I guess we can’t resolve that easily unless the XPointer support is improved in a future version of Java. As you may have seen, the referenced document will be fully included if you remove the xpointer attribute, but that’s probably not what you need. Out of interest, I checked if Saxon can handle XPointer attributes. As it relies on the default parser as well, it returns the same error message as BaseX. I remember there have been previous posts on that issue; e.g here [1]. Sorry for that! Christian [1] https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021.html
Quoted text · Christian Grün · 8 lines
On Wed, Feb 17, 2021 at 10:03 AM Christian Grün <christian.gruen at gmail.com> wrote: > > > When I add the file into BaseX I now have the following message when adding the main file into BaseX. > > > > > An include with href 'EP15.xml'failed, and no fallback element was found. > > Feel free to send us/me the files in question, I can have a look at that.
P
pascaljoubaud17 Feb 2021 20:36 #
Hi Christian, Yes ideally I was hoping for the xpointer to work but I read in previous posts that instead of a named element [element(EP15)], i could use descendent path notation [element(1/2/1/1)] and that it should work. That's not ideal but in my case, I think it will work (all the files are structured in a very similar way). https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607.html My problem is that the referenced document IS NOT included at all if i remove the xpointer attribute (I have the same error message). As it works on your side, I guess my baseX installation is not good. I think I'll have a look at that. One more question : I understand that baseX "resolves" the xinclude when adding the file into the database. But later, if I change the source files (the ones I call from the main one), will the main file be changed dynamically ? or do I need to reload this main file to baseX to perform the xinclude operations again ? If answer 2, I guess I could just resolve the xinclude before loading into baseX (in a dedicated xsl) and load the result in baseX, would it make a difference ? Thanks Pascal -----Message d'origine-----
Quoted text · Christian Grün · 19 lines
De : Christian Grün <christian.gruen at gmail.com> Envoyé : mercredi 17 février 2021 19:18 À : pascaljoubaud at gmail.com Cc : BaseX <basex-talk at mailman.uni-konstanz.de> Objet : Re: [basex-talk] BaseX, xinclude and xpointer Hi Pascal, Thanks for the sample files. The error you reported is returned by Java’s default XML parser (the one from Xerces), so I guess we can’t resolve that easily unless the XPointer support is improved in a future version of Java. As you may have seen, the referenced document will be fully included if you remove the xpointer attribute, but that’s probably not what you need. Out of interest, I checked if Saxon can handle XPointer attributes. As it relies on the default parser as well, it returns the same error message as BaseX. I remember there have been previous posts on that issue; e.g here [1]. Sorry for that! Christian [1] https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021.html On Wed, Feb 17, 2021 at 10:03 AM Christian Grün <christian.gruen at gmail.com> wrote: > > > When I add the file into BaseX I now have the following message when adding the main file into BaseX. > > > > > An include with href 'EP15.xml'failed, and no fallback element was found. > > Feel free to send us/me the files in question, I can have a look at that.
CG
Christian Grün18 Feb 2021 11:11 #
Hi Pascal,
Quoted text · pascaljoubaud · 1 line
> My problem is that the referenced document IS NOT included at all if i remove the xpointer attribute (I have the same error message). As it works on your side, I guess my baseX installation is not good. I think I'll have a look at that.
Here’s a minimized test case on command line. Do you still get the same error for that one? doc.xml:
<main xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="include.xml"/>
</main>
include.xml: <include/> Query:
Quoted text · pascaljoubaud · 1 line
> basex "doc('doc.xml')"
<main xmlns:xi="http://www.w3.org/2001/XInclude">
  <included xml:base="include.xml"/>
</main>
Ideally, the include should work no matter if fn:doc is called or if a new database is created (at least with OpenJDK).
Quoted text · pascaljoubaud · 1 line
> One more question : I understand that baseX "resolves" the xinclude when adding the file into the database. But later, if I change the source files (the ones I call from the main one), will the main file be changed dynamically ? or do I need to reload this main file to baseX to perform the xinclude operations again ?
You’ll need to reload the file. The references will be fully resolved, and the file will get embedded in the mail file.
Quoted text · pascaljoubaud · 1 line
> If answer 2, I guess I could just resolve the xinclude before loading into baseX (in a dedicated xsl) and load the result in baseX, would it make a difference ?
Absolutely. Or you can do everything in XQuery. Here’s one quick’n’dirty solution to achieve that:
declare namespace xi = 'http://www.w3.org/2001/XInclude';
declare option db:xinclude 'false';

let $doc := doc('EV.xml') update {
  for $inc in .//xi:include
  let $id := replace($inc/@xpointer, '.*\(|\)', '')
  let $included-doc := doc($inc/@href)
  return replace node $inc with id($id, $included-doc)
}
return (
  $doc
  (: write to database...
  db:create('db', $doc, 'doc.xml') :)
  (: write back to file...
  file:write('doc.xml', $doc) :)
)
If you want to work with documents in the database, the doc() calls can e.g. be replaced with db:open('db', 'doc.xml') calls. Hope this helps, Christian
Quoted text · pascaljoubaud at gmail.com · 66 lines
On 2/17/21, pascaljoubaud at gmail.com <pascaljoubaud at gmail.com> wrote: > Hi Christian, > Yes ideally I was hoping for the xpointer to work but I read in previous > posts that instead of a named element [element(EP15)], i could use > descendent path notation [element(1/2/1/1)] and that it should work. That's > not ideal but in my case, I think it will work (all the files are > structured in a very similar way). > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607.html > My problem is that the referenced document IS NOT included at all if i > remove the xpointer attribute (I have the same error message). As it works > on your side, I guess my baseX installation is not good. I think I'll have a > look at that. > > One more question : I understand that baseX "resolves" the xinclude when > adding the file into the database. But later, if I change the source files > (the ones I call from the main one), will the main file be changed > dynamically ? or do I need to reload this main file to baseX to perform the > xinclude operations again ? > If answer 2, I guess I could just resolve the xinclude before loading into > baseX (in a dedicated xsl) and load the result in baseX, would it make a > difference ? > > Thanks > Pascal > > -----Message d'origine----- > De : Christian Grün <christian.gruen at gmail.com> > Envoyé : mercredi 17 février 2021 19:18 > À : pascaljoubaud at gmail.com > Cc : BaseX <basex-talk at mailman.uni-konstanz.de> > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > Hi Pascal, > > Thanks for the sample files. The error you reported is returned by Java’s > default XML parser (the one from Xerces), so I guess we can’t resolve that > easily unless the XPointer support is improved in a future version of Java. > As you may have seen, the referenced document will be fully included if you > remove the xpointer attribute, but that’s probably not what you need. > > Out of interest, I checked if Saxon can handle XPointer attributes. As it > relies on the default parser as well, it returns the same error message as > BaseX. > > I remember there have been previous posts on that issue; e.g here [1]. > > Sorry for that! > Christian > > [1] > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021.html > > > > On Wed, Feb 17, 2021 at 10:03 AM Christian Grün <christian.gruen at gmail.com> > wrote: >> >> > When I add the file into BaseX I now have the following message when >> > adding the main file into BaseX. >> > >> > > An include with href 'EP15.xml'failed, and no fallback element was >> > > found. >> >> Feel free to send us/me the files in question, I can have a look at that. > >
P
pascaljoubaud18 Feb 2021 16:53 #
Thanks Christian,
Quoted text · Christian Grün · 1 line
> Here’s a minimized test case on command line. Do you still get the same error for that one?
Well this one works. And I've tried the same command with my files basex "doc('EV.xml')" and the inclusion works too. Nevertheless, I have strange warnings : [warning] /usr/bin/basex: Unable to locate /usr/share/java/tagsoup.jar in /usr/share/java [warning] /usr/bin/basex: Unable to locate /usr/share/java/xml-resolver.jar in /usr/share/java [warning] /usr/bin/basex: Unable to locate /usr/share/java/jing.jar in /usr/share/java Could that be the cause of my problems when adding files to the database ? Thanks for the other answers. Pascal -----Message d'origine-----
Quoted text · Christian Grün · 107 lines
De : Christian Grün <christian.gruen at gmail.com> Envoyé : jeudi 18 février 2021 11:11 À : pascaljoubaud at gmail.com Cc : BaseX <basex-talk at mailman.uni-konstanz.de> Objet : Re: [basex-talk] BaseX, xinclude and xpointer Hi Pascal, > My problem is that the referenced document IS NOT included at all if i remove the xpointer attribute (I have the same error message). As it works on your side, I guess my baseX installation is not good. I think I'll have a look at that. Here’s a minimized test case on command line. Do you still get the same error for that one? doc.xml: <main xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="include.xml"/> </main> include.xml: <include/> Query: > basex "doc('doc.xml')" <main xmlns:xi="http://www.w3.org/2001/XInclude"> <included xml:base="include.xml"/> </main> Ideally, the include should work no matter if fn:doc is called or if a new database is created (at least with OpenJDK). > One more question : I understand that baseX "resolves" the xinclude when adding the file into the database. But later, if I change the source files (the ones I call from the main one), will the main file be changed dynamically ? or do I need to reload this main file to baseX to perform the xinclude operations again ? You’ll need to reload the file. The references will be fully resolved, and the file will get embedded in the mail file. > If answer 2, I guess I could just resolve the xinclude before loading into baseX (in a dedicated xsl) and load the result in baseX, would it make a difference ? Absolutely. Or you can do everything in XQuery. Here’s one quick’n’dirty solution to achieve that: declare namespace xi = 'http://www.w3.org/2001/XInclude'; declare option db:xinclude 'false'; let $doc := doc('EV.xml') update { for $inc in .//xi:include let $id := replace($inc/@xpointer, '.*\(|\)', '') let $included-doc := doc($inc/@href) return replace node $inc with id($id, $included-doc) } return ( $doc (: write to database... db:create('db', $doc, 'doc.xml') :) (: write back to file... file:write('doc.xml', $doc) :) ) If you want to work with documents in the database, the doc() calls can e.g. be replaced with db:open('db', 'doc.xml') calls. Hope this helps, Christian On 2/17/21, pascaljoubaud at gmail.com <pascaljoubaud at gmail.com> wrote: > Hi Christian, > Yes ideally I was hoping for the xpointer to work but I read in > previous posts that instead of a named element [element(EP15)], i > could use descendent path notation [element(1/2/1/1)] and that it > should work. That's not ideal but in my case, I think it will work > (all the files are structured in a very similar way). > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607 > .html My problem is that the referenced document IS NOT included at > all if i remove the xpointer attribute (I have the same error > message). As it works on your side, I guess my baseX installation is > not good. I think I'll have a look at that. > > One more question : I understand that baseX "resolves" the xinclude > when adding the file into the database. But later, if I change the > source files (the ones I call from the main one), will the main file > be changed dynamically ? or do I need to reload this main file to > baseX to perform the xinclude operations again ? > If answer 2, I guess I could just resolve the xinclude before loading > into baseX (in a dedicated xsl) and load the result in baseX, would it > make a difference ? > > Thanks > Pascal > > -----Message d'origine----- > De : Christian Grün <christian.gruen at gmail.com> Envoyé : mercredi 17 > février 2021 19:18 À : pascaljoubaud at gmail.com Cc : BaseX > <basex-talk at mailman.uni-konstanz.de> > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > Hi Pascal, > > Thanks for the sample files. The error you reported is returned by > Java’s default XML parser (the one from Xerces), so I guess we can’t > resolve that easily unless the XPointer support is improved in a future version of Java. > As you may have seen, the referenced document will be fully included > if you remove the xpointer attribute, but that’s probably not what you need. > > Out of interest, I checked if Saxon can handle XPointer attributes. As > it relies on the default parser as well, it returns the same error > message as BaseX. > > I remember there have been previous posts on that issue; e.g here [1]. > > Sorry for that! > Christian > > [1] > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021. > html > > > > On Wed, Feb 17, 2021 at 10:03 AM Christian Grün > <christian.gruen at gmail.com> > wrote: >> >> > When I add the file into BaseX I now have the following message >> > when adding the main file into BaseX. >> > >> > > An include with href 'EP15.xml'failed, and no fallback element >> > > was found. >> >> Feel free to send us/me the files in question, I can have a look at that. > >
CG
Christian Grün18 Feb 2021 17:00 #
Quoted text · pascaljoubaud · 3 lines
> > Nevertheless, I have strange warnings : >
Which of our distributions are you using? With the ZIP distribution, all libraries should be correctly added to the classpath. But I guess that won't solve your xinclude issue. Maybe you can find out more by comparing my minimized example with your setup. Cheers, Christian
Quoted text · pascaljoubaud · 158 lines
> [warning] /usr/bin/basex: Unable to locate /usr/share/java/tagsoup.jar in > /usr/share/java > [warning] /usr/bin/basex: Unable to locate > /usr/share/java/xml-resolver.jar in /usr/share/java > [warning] /usr/bin/basex: Unable to locate /usr/share/java/jing.jar in > /usr/share/java > > Could that be the cause of my problems when adding files to the database ? > > Thanks for the other answers. > > Pascal > > -----Message d'origine----- > De : Christian Grün <christian.gruen at gmail.com> > Envoyé : jeudi 18 février 2021 11:11 > À : pascaljoubaud at gmail.com > Cc : BaseX <basex-talk at mailman.uni-konstanz.de> > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > Hi Pascal, > > > My problem is that the referenced document IS NOT included at all if i > remove the xpointer attribute (I have the same error message). As it works > on your side, I guess my baseX installation is not good. I think I'll have > a look at that. > > Here’s a minimized test case on command line. Do you still get the same > error for that one? > > doc.xml: > <main xmlns:xi="http://www.w3.org/2001/XInclude"> > <xi:include href="include.xml"/> > </main> > > include.xml: > <include/> > > Query: > > basex "doc('doc.xml')" > <main xmlns:xi="http://www.w3.org/2001/XInclude"> > <included xml:base="include.xml"/> > </main> > > Ideally, the include should work no matter if fn:doc is called or if a new > database is created (at least with OpenJDK). > > > One more question : I understand that baseX "resolves" the xinclude when > adding the file into the database. But later, if I change the source files > (the ones I call from the main one), will the main file be changed > dynamically ? or do I need to reload this main file to baseX to perform the > xinclude operations again ? > > You’ll need to reload the file. The references will be fully resolved, and > the file will get embedded in the mail file. > > > If answer 2, I guess I could just resolve the xinclude before loading > into baseX (in a dedicated xsl) and load the result in baseX, would it make > a difference ? > > Absolutely. Or you can do everything in XQuery. Here’s one quick’n’dirty > solution to achieve that: > > declare namespace xi = 'http://www.w3.org/2001/XInclude'; > declare option db:xinclude 'false'; > > let $doc := doc('EV.xml') update { > for $inc in .//xi:include > let $id := replace($inc/@xpointer, '.*\(|\)', '') > let $included-doc := doc($inc/@href) > return replace node $inc with id($id, $included-doc) } return ( > $doc > (: write to database... > db:create('db', $doc, 'doc.xml') :) > (: write back to file... > file:write('doc.xml', $doc) :) > ) > > If you want to work with documents in the database, the doc() calls can > e.g. be replaced with db:open('db', 'doc.xml') calls. > > Hope this helps, > Christian > > > > On 2/17/21, pascaljoubaud at gmail.com <pascaljoubaud at gmail.com> wrote: > > Hi Christian, > > Yes ideally I was hoping for the xpointer to work but I read in > > previous posts that instead of a named element [element(EP15)], i > > could use descendent path notation [element(1/2/1/1)] and that it > > should work. That's not ideal but in my case, I think it will work > > (all the files are structured in a very similar way). > > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607 > > .html My problem is that the referenced document IS NOT included at > > all if i remove the xpointer attribute (I have the same error > > message). As it works on your side, I guess my baseX installation is > > not good. I think I'll have a look at that. > > > > One more question : I understand that baseX "resolves" the xinclude > > when adding the file into the database. But later, if I change the > > source files (the ones I call from the main one), will the main file > > be changed dynamically ? or do I need to reload this main file to > > baseX to perform the xinclude operations again ? > > If answer 2, I guess I could just resolve the xinclude before loading > > into baseX (in a dedicated xsl) and load the result in baseX, would it > > make a difference ? > > > > Thanks > > Pascal > > > > -----Message d'origine----- > > De : Christian Grün <christian.gruen at gmail.com> Envoyé : mercredi 17 > > février 2021 19:18 À : pascaljoubaud at gmail.com Cc : BaseX > > <basex-talk at mailman.uni-konstanz.de> > > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > > > Hi Pascal, > > > > Thanks for the sample files. The error you reported is returned by > > Java’s default XML parser (the one from Xerces), so I guess we can’t > > resolve that easily unless the XPointer support is improved in a future > version of Java. > > As you may have seen, the referenced document will be fully included > > if you remove the xpointer attribute, but that’s probably not what you > need. > > > > Out of interest, I checked if Saxon can handle XPointer attributes. As > > it relies on the default parser as well, it returns the same error > > message as BaseX. > > > > I remember there have been previous posts on that issue; e.g here [1]. > > > > Sorry for that! > > Christian > > > > [1] > > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021. > > html > > > > > > > > On Wed, Feb 17, 2021 at 10:03 AM Christian Grün > > <christian.gruen at gmail.com> > > wrote: > >> > >> > When I add the file into BaseX I now have the following message > >> > when adding the main file into BaseX. > >> > > >> > > An include with href 'EP15.xml'failed, and no fallback element > >> > > was found. > >> > >> Feel free to send us/me the files in question, I can have a look at > that. > > > > > >
P
pascaljoubaud19 Feb 2021 08:57 #
Some good news, I managed to get the include working when adding the files (either the minimized ones or my own files) using a command line or the basexGUI. Unfortunately, i still have the error message when using the web interface (which is the only one I was using initially) and cannot figure out why. Pascal
Quoted text · Christian Grün · 124 lines
De : Christian Grün <christian.gruen at gmail.com> Envoyé : jeudi 18 février 2021 17:01 À : pascaljoubaud at gmail.com Cc : BaseX <basex-talk at mailman.uni-konstanz.de> Objet : Re: [basex-talk] BaseX, xinclude and xpointer Nevertheless, I have strange warnings : Which of our distributions are you using? With the ZIP distribution, all libraries should be correctly added to the classpath. But I guess that won't solve your xinclude issue. Maybe you can find out more by comparing my minimized example with your setup. Cheers, Christian [warning] /usr/bin/basex: Unable to locate /usr/share/java/tagsoup.jar in /usr/share/java [warning] /usr/bin/basex: Unable to locate /usr/share/java/xml-resolver.jar in /usr/share/java [warning] /usr/bin/basex: Unable to locate /usr/share/java/jing.jar in /usr/share/java Could that be the cause of my problems when adding files to the database ? Thanks for the other answers. Pascal -----Message d'origine----- De : Christian Grün <christian.gruen at gmail.com <mailto:christian.gruen at gmail.com> > Envoyé : jeudi 18 février 2021 11:11 À : pascaljoubaud at gmail.com <mailto:pascaljoubaud at gmail.com> Cc : BaseX <basex-talk at mailman.uni-konstanz.de <mailto:basex-talk at mailman.uni-konstanz.de> > Objet : Re: [basex-talk] BaseX, xinclude and xpointer Hi Pascal, > My problem is that the referenced document IS NOT included at all if i remove the xpointer attribute (I have the same error message). As it works on your side, I guess my baseX installation is not good. I think I'll have a look at that. Here’s a minimized test case on command line. Do you still get the same error for that one? doc.xml: <main xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="include.xml"/> </main> include.xml: <include/> Query: > basex "doc('doc.xml')" <main xmlns:xi="http://www.w3.org/2001/XInclude"> <included xml:base="include.xml"/> </main> Ideally, the include should work no matter if fn:doc is called or if a new database is created (at least with OpenJDK). > One more question : I understand that baseX "resolves" the xinclude when adding the file into the database. But later, if I change the source files (the ones I call from the main one), will the main file be changed dynamically ? or do I need to reload this main file to baseX to perform the xinclude operations again ? You’ll need to reload the file. The references will be fully resolved, and the file will get embedded in the mail file. > If answer 2, I guess I could just resolve the xinclude before loading into baseX (in a dedicated xsl) and load the result in baseX, would it make a difference ? Absolutely. Or you can do everything in XQuery. Here’s one quick’n’dirty solution to achieve that: declare namespace xi = 'http://www.w3.org/2001/XInclude'; declare option db:xinclude 'false'; let $doc := doc('EV.xml') update { for $inc in .//xi:include let $id := replace($inc/@xpointer, '.*\(|\)', '') let $included-doc := doc($inc/@href) return replace node $inc with id($id, $included-doc) } return ( $doc (: write to database... db:create('db', $doc, 'doc.xml') :) (: write back to file... file:write('doc.xml', $doc) :) ) If you want to work with documents in the database, the doc() calls can e.g. be replaced with db:open('db', 'doc.xml') calls. Hope this helps, Christian On 2/17/21, pascaljoubaud at gmail.com <mailto:pascaljoubaud at gmail.com> <pascaljoubaud at gmail.com <mailto:pascaljoubaud at gmail.com> > wrote: > Hi Christian, > Yes ideally I was hoping for the xpointer to work but I read in > previous posts that instead of a named element [element(EP15)], i > could use descendent path notation [element(1/2/1/1)] and that it > should work. That's not ideal but in my case, I think it will work > (all the files are structured in a very similar way). > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607 > .html My problem is that the referenced document IS NOT included at > all if i remove the xpointer attribute (I have the same error > message). As it works on your side, I guess my baseX installation is > not good. I think I'll have a look at that. > > One more question : I understand that baseX "resolves" the xinclude > when adding the file into the database. But later, if I change the > source files (the ones I call from the main one), will the main file > be changed dynamically ? or do I need to reload this main file to > baseX to perform the xinclude operations again ? > If answer 2, I guess I could just resolve the xinclude before loading > into baseX (in a dedicated xsl) and load the result in baseX, would it > make a difference ? > > Thanks > Pascal > > -----Message d'origine----- > De : Christian Grün <christian.gruen at gmail.com <mailto:christian.gruen at gmail.com> > Envoyé : mercredi 17 > février 2021 19:18 À : pascaljoubaud at gmail.com <mailto:pascaljoubaud at gmail.com> Cc : BaseX > <basex-talk at mailman.uni-konstanz.de <mailto:basex-talk at mailman.uni-konstanz.de> > > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > Hi Pascal, > > Thanks for the sample files. The error you reported is returned by > Java’s default XML parser (the one from Xerces), so I guess we can’t > resolve that easily unless the XPointer support is improved in a future version of Java. > As you may have seen, the referenced document will be fully included > if you remove the xpointer attribute, but that’s probably not what you need. > > Out of interest, I checked if Saxon can handle XPointer attributes. As > it relies on the default parser as well, it returns the same error > message as BaseX. > > I remember there have been previous posts on that issue; e.g here [1]. > > Sorry for that! > Christian > > [1] > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021. > html > > > > On Wed, Feb 17, 2021 at 10:03 AM Christian Grün > <christian.gruen at gmail.com <mailto:christian.gruen at gmail.com> > > wrote: >> >> > When I add the file into BaseX I now have the following message >> > when adding the main file into BaseX. >> > >> > > An include with href 'EP15.xml'failed, and no fallback element >> > > was found. >> >> Feel free to send us/me the files in question, I can have a look at that. > >
CG
Christian Grün19 Feb 2021 20:42 #
I see; you are talking about the DBA? As the web interface may be located on another server, the XML parser will fall to resolve the xinclude href reference (unless you specify an absolute file path). In that case, the better solution will certainly be to preprocess your data.
Quoted text · pascaljoubaud · 206 lines
<pascaljoubaud at gmail.com> schrieb am Fr., 19. Feb. 2021, 08:57: > Some good news, > > I managed to get the include working when adding the files (either the > minimized ones or my own files) using a command line or the basexGUI. > > Unfortunately, i still have the error message when using the web interface > (which is the only one I was using initially) and cannot figure out why. > > > > Pascal > > > > > > *De :* Christian Grün <christian.gruen at gmail.com> > *Envoyé :* jeudi 18 février 2021 17:01 > *À :* pascaljoubaud at gmail.com > *Cc :* BaseX <basex-talk at mailman.uni-konstanz.de> > *Objet :* Re: [basex-talk] BaseX, xinclude and xpointer > > > > Nevertheless, I have strange warnings : > > > > Which of our distributions are you using? With the ZIP distribution, all > libraries should be correctly added to the classpath. > > > > But I guess that won't solve your xinclude issue. Maybe you can find out > more by comparing my minimized example with your setup. > > > > Cheers, > > Christian > > > > > > > [warning] /usr/bin/basex: Unable to locate /usr/share/java/tagsoup.jar in > /usr/share/java > [warning] /usr/bin/basex: Unable to locate > /usr/share/java/xml-resolver.jar in /usr/share/java > [warning] /usr/bin/basex: Unable to locate /usr/share/java/jing.jar in > /usr/share/java > > Could that be the cause of my problems when adding files to the database ? > > Thanks for the other answers. > > Pascal > > -----Message d'origine----- > De : Christian Grün <christian.gruen at gmail.com> > Envoyé : jeudi 18 février 2021 11:11 > À : pascaljoubaud at gmail.com > Cc : BaseX <basex-talk at mailman.uni-konstanz.de> > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > Hi Pascal, > > > My problem is that the referenced document IS NOT included at all if i > remove the xpointer attribute (I have the same error message). As it works > on your side, I guess my baseX installation is not good. I think I'll have > a look at that. > > Here’s a minimized test case on command line. Do you still get the same > error for that one? > > doc.xml: > <main xmlns:xi="http://www.w3.org/2001/XInclude"> > <xi:include href="include.xml"/> > </main> > > include.xml: > <include/> > > Query: > > basex "doc('doc.xml')" > <main xmlns:xi="http://www.w3.org/2001/XInclude"> > <included xml:base="include.xml"/> > </main> > > Ideally, the include should work no matter if fn:doc is called or if a new > database is created (at least with OpenJDK). > > > One more question : I understand that baseX "resolves" the xinclude when > adding the file into the database. But later, if I change the source files > (the ones I call from the main one), will the main file be changed > dynamically ? or do I need to reload this main file to baseX to perform the > xinclude operations again ? > > You’ll need to reload the file. The references will be fully resolved, and > the file will get embedded in the mail file. > > > If answer 2, I guess I could just resolve the xinclude before loading > into baseX (in a dedicated xsl) and load the result in baseX, would it make > a difference ? > > Absolutely. Or you can do everything in XQuery. Here’s one quick’n’dirty > solution to achieve that: > > declare namespace xi = 'http://www.w3.org/2001/XInclude'; > declare option db:xinclude 'false'; > > let $doc := doc('EV.xml') update { > for $inc in .//xi:include > let $id := replace($inc/@xpointer, '.*\(|\)', '') > let $included-doc := doc($inc/@href) > return replace node $inc with id($id, $included-doc) } return ( > $doc > (: write to database... > db:create('db', $doc, 'doc.xml') :) > (: write back to file... > file:write('doc.xml', $doc) :) > ) > > If you want to work with documents in the database, the doc() calls can > e.g. be replaced with db:open('db', 'doc.xml') calls. > > Hope this helps, > Christian > > > > On 2/17/21, pascaljoubaud at gmail.com <pascaljoubaud at gmail.com> wrote: > > Hi Christian, > > Yes ideally I was hoping for the xpointer to work but I read in > > previous posts that instead of a named element [element(EP15)], i > > could use descendent path notation [element(1/2/1/1)] and that it > > should work. That's not ideal but in my case, I think it will work > > (all the files are structured in a very similar way). > > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-April/008607 > > .html My problem is that the referenced document IS NOT included at > > all if i remove the xpointer attribute (I have the same error > > message). As it works on your side, I guess my baseX installation is > > not good. I think I'll have a look at that. > > > > One more question : I understand that baseX "resolves" the xinclude > > when adding the file into the database. But later, if I change the > > source files (the ones I call from the main one), will the main file > > be changed dynamically ? or do I need to reload this main file to > > baseX to perform the xinclude operations again ? > > If answer 2, I guess I could just resolve the xinclude before loading > > into baseX (in a dedicated xsl) and load the result in baseX, would it > > make a difference ? > > > > Thanks > > Pascal > > > > -----Message d'origine----- > > De : Christian Grün <christian.gruen at gmail.com> Envoyé : mercredi 17 > > février 2021 19:18 À : pascaljoubaud at gmail.com Cc : BaseX > > <basex-talk at mailman.uni-konstanz.de> > > Objet : Re: [basex-talk] BaseX, xinclude and xpointer > > > > Hi Pascal, > > > > Thanks for the sample files. The error you reported is returned by > > Java’s default XML parser (the one from Xerces), so I guess we can’t > > resolve that easily unless the XPointer support is improved in a future > version of Java. > > As you may have seen, the referenced document will be fully included > > if you remove the xpointer attribute, but that’s probably not what you > need. > > > > Out of interest, I checked if Saxon can handle XPointer attributes. As > > it relies on the default parser as well, it returns the same error > > message as BaseX. > > > > I remember there have been previous posts on that issue; e.g here [1]. > > > > Sorry for that! > > Christian > > > > [1] > > https://mailman.uni-konstanz.de/pipermail/basex-talk/2015-June/009021. > > html > > > > > > > > On Wed, Feb 17, 2021 at 10:03 AM Christian Grün > > <christian.gruen at gmail.com> > > wrote: > >> > >> > When I add the file into BaseX I now have the following message > >> > when adding the main file into BaseX. > >> > > >> > > An include with href 'EP15.xml'failed, and no fallback element > >> > > was found. > >> > >> Feel free to send us/me the files in question, I can have a look at > that. > > > > > >

⚡Generated with XQuery