id function in BaseX

Monday, 29 October 2012 · 5 messages · last reply 31 Oct 2012
MF
Massimo Franceschet29 Oct 2012 13:49 #
Hi. I'm trying to use the XPath id function with BaseX (GUI interface) with no success. For instance, I'm querying the bibliographic XML document found at http://users.dimi.uniud.it/~massimo.franceschet/caffe-xml/xpath/xpath-syntax3.html with the id queries written below in this page, for instance, id("M4M05"). The query is parsed correctly by BaseX but the result is always empty. Cheers, Massimo Franceschet
BC
Ben Companjen29 Oct 2012 19:22 #
This is just a guess, but did you include the DTD? As the document says: "Notice that the id() functions works only if you have properly declared the ID and IDREF attributes in the document DTD." Ben
Quoted text · Massimo Franceschet · 13 lines
On 29 October 2012 13:49, Massimo Franceschet <massimo.franceschet at uniud.it> wrote: > Hi. > > I'm trying to use the XPath id function with BaseX (GUI interface) with no success. For instance, I'm querying the bibliographic XML document found at http://users.dimi.uniud.it/~massimo.franceschet/caffe-xml/xpath/xpath-syntax3.html with the id queries written below in this page, for instance, id("M4M05"). The query is parsed correctly by BaseX but the result is always empty. > > Cheers, > > Massimo Franceschet > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
MS
Michael Seiferle31 Oct 2012 14:39 #
Hi Massimo, Hi Ben, BaseX has no direct support for extracting the information, that for a given document the ID is renamed to "@key" (even with help of a DTD). This is why those example queries fail to function as expected. BaseX will however work if the ID attribute is named @id. Long story short: you can mimic this behaviour, which you might have already known by running:
Quoted text · Ben Companjen · 5 lines
> declare function local:id($id as xs:string, > $nodes as node()){ > $nodes//*[@key = $id] > }; > local:id("M4M05", .)
or if you do not want to wrap it in a function,
Quoted text · Ben Companjen · 1 line
> //*[@key = "M4M05"]
Hope this helps Michael
Quoted text · Ben Companjen · 24 lines
Am 29.10.2012 um 19:22 schrieb Ben Companjen <bencompanjen at gmail.com>: > This is just a guess, but did you include the DTD? As the document > says: "Notice that the id() functions works only if you have properly > declared the ID and IDREF attributes in the document DTD." > > Ben > > On 29 October 2012 13:49, Massimo Franceschet > <massimo.franceschet at uniud.it> wrote: >> Hi. >> >> I'm trying to use the XPath id function with BaseX (GUI interface) with no success. For instance, I'm querying the bibliographic XML document found at http://users.dimi.uniud.it/~massimo.franceschet/caffe-xml/xpath/xpath-syntax3.html with the id queries written below in this page, for instance, id("M4M05"). The query is parsed correctly by BaseX but the result is always empty. >> >> Cheers, >> >> Massimo Franceschet >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
MF
Massimo Franceschet31 Oct 2012 14:44 #
Quoted text · Michael Seiferle · 6 lines
Il giorno 31/ott/2012, alle ore 14:39, Michael Seiferle ha scritto: > Hi Massimo, > Hi Ben, > > BaseX has no direct support for extracting the information, that for a given document the ID is renamed to "@key" (even with help of a DTD). > This is why those example queries fail to function as expected. BaseX will however work if the ID attribute is named @id.
Thanks Michael, this explains the failure. Strange behavior, anyway. I know that ID-type attributes can have any name, not necessarily the name id. Is BaseX behavior coherent with W3C specifications? Best, Massimo
MS
Michael Seiferle31 Oct 2012 14:53 #
Hi Massimo, sorry, I'm a little in a hurry: The spec states:
Quoted text · Massimo Franceschet · 2 lines
> http://www.w3.org/TR/xpath-datamodel/#dm-is-id > Exactly what constitutes an ID depends in part on how the data model was constructed, see 6.2 Element Nodes and 6.3 Attribute Nodes.
which says:
Quoted text · Massimo Franceschet · 2 lines
> is-id > If the attribute is named xml:id and its [attribute type] property does not have the value ID, then [xml:id] processing is performed. This will assure that the value does have the type ID and that it is properly normalized. If an error is encountered during xml:id processing, an implementation may raise a dynamic error. The is-id property is always true for attributes named xml:id.
as BaseX does not check/care for the types when parsing, we follow:
Quoted text · Massimo Franceschet · 1 line
>> The is-id property is always true for attributes named xml:id.
I hope I read the spec right; others will correct me :-) Best Michael
Quoted text · Massimo Franceschet · 15 lines
Am 31.10.2012 um 14:44 schrieb Massimo Franceschet <massimo.franceschet at uniud.it>: > > Il giorno 31/ott/2012, alle ore 14:39, Michael Seiferle ha scritto: > >> Hi Massimo, >> Hi Ben, >> >> BaseX has no direct support for extracting the information, that for a given document the ID is renamed to "@key" (even with help of a DTD). >> This is why those example queries fail to function as expected. BaseX will however work if the ID attribute is named @id. > > Thanks Michael, this explains the failure. Strange behavior, anyway. I know that ID-type attributes can have any name, not necessarily the name id. Is BaseX behavior coherent with W3C specifications? > > Best, > > Massimo

⚡Generated with XQuery