Question about namespace prefix bindings

Wednesday, 6 January 2016 · 3 messages · last reply 7 Jan 2016
TT
Tim Thompson6 Jan 2016 19:32 #
Hello, I have a small database of library catalog records that I am trying to run some simple queries on, but I'm running into a namespace problem. Some docs in the database have the following structure, with a wrapper collection element and two record elements: <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> <marc:record type="Bibliographic"> ... </marc:record> <marc:record type="Holdings"> ... </marc:record> </marc:collection> But others lack a wrapper collection and have only a single record element, which also lacks a namespace declaration, like so:
<marc:record type="Bibliographic">
    ...
</marc:record>
So, I run the following query (using the DBA query interface):
declare namespace marc = "http://www.loc.gov/MARC21/slim";

let $m := collection("marc-data")/marc:record[@type = "Bibliographic"]
return count($m)
And the count returns 0. However, if I change the predicate in the let clause to: let $m := collection("marc-data")/*[local-name() = "record"][@type = "Bibliographic"] the count returns 45. If I am declaring the namespace in my query prolog and associating it with the same prefix as the one used in my XML documents, why don't I get the desired prefix/namespace mapping? I'm probably missing something basic, but this didn't immediately make sense to me. Thank you, Tim
-- Tim A. Thompson Metadata Librarian (Spanish/Portuguese Specialty) Princeton University Library
TT
Tim Thompson7 Jan 2016 03:55 #
Sorry, never mind. I see that the documents that lack are namespace declarations are just not well formed. Actually, I'm a little surprised that it was possible to save them to the DB in the first place! Thanks, Tim
-- Tim A. Thompson Metadata Librarian (Spanish/Portuguese Specialty) Princeton University Library
Quoted text · Tim Thompson · 58 lines
On Wed, Jan 6, 2016 at 12:32 PM, Tim Thompson <timathom at gmail.com> wrote: > Hello, > > I have a small database of library catalog records that I am trying to run > some simple queries on, but I'm running into a namespace problem. > > Some docs in the database have the following structure, with a wrapper > collection element and two record elements: > > <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi=" > http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" > http://www.loc.gov/MARC21/slim > http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> > <marc:record type="Bibliographic"> > ... > </marc:record> > <marc:record type="Holdings"> > ... > </marc:record> > </marc:collection> > > But others lack a wrapper collection and have only a single record > element, which also lacks a namespace declaration, like so: > > <marc:record type="Bibliographic"> > ... > </marc:record> > > So, I run the following query (using the DBA query interface): > > declare namespace marc = "http://www.loc.gov/MARC21/slim"; > > let $m := collection("marc-data")/marc:record[@type = "Bibliographic"] > return count($m) > > And the count returns 0. However, if I change the predicate in the let > clause to: > > let $m := collection("marc-data")/*[local-name() = "record"][@type = > "Bibliographic"] > > the count returns 45. > > If I am declaring the namespace in my query prolog and associating it with > the same prefix as the one used in my XML documents, why don't I get the > desired prefix/namespace mapping? I'm probably missing something basic, but > this didn't immediately make sense to me. > > Thank you, > Tim > > > -- > Tim A. Thompson > Metadata Librarian (Spanish/Portuguese Specialty) > Princeton University Library > >
CG
Christian Grün7 Jan 2016 09:04 #
Quoted text · Tim Thompson · 3 lines
> I see that the documents that lack are namespace > declarations are just not well formed. Actually, I'm a little surprised that > it was possible to save them to the DB in the first place!
Interesting; how did you manage that? ;) Christian
Quoted text · Tim Thompson · 69 lines
> > Thanks, > Tim > > -- > Tim A. Thompson > Metadata Librarian (Spanish/Portuguese Specialty) > Princeton University Library > > > On Wed, Jan 6, 2016 at 12:32 PM, Tim Thompson <timathom at gmail.com> wrote: >> >> Hello, >> >> I have a small database of library catalog records that I am trying to run >> some simple queries on, but I'm running into a namespace problem. >> >> Some docs in the database have the following structure, with a wrapper >> collection element and two record elements: >> >> <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:schemaLocation="http://www.loc.gov/MARC21/slim >> http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> >> <marc:record type="Bibliographic"> >> ... >> </marc:record> >> <marc:record type="Holdings"> >> ... >> </marc:record> >> </marc:collection> >> >> But others lack a wrapper collection and have only a single record >> element, which also lacks a namespace declaration, like so: >> >> <marc:record type="Bibliographic"> >> ... >> </marc:record> >> >> So, I run the following query (using the DBA query interface): >> >> declare namespace marc = "http://www.loc.gov/MARC21/slim"; >> >> let $m := collection("marc-data")/marc:record[@type = "Bibliographic"] >> return count($m) >> >> And the count returns 0. However, if I change the predicate in the let >> clause to: >> >> let $m := collection("marc-data")/*[local-name() = "record"][@type = >> "Bibliographic"] >> >> the count returns 45. >> >> If I am declaring the namespace in my query prolog and associating it with >> the same prefix as the one used in my XML documents, why don't I get the >> desired prefix/namespace mapping? I'm probably missing something basic, but >> this didn't immediately make sense to me. >> >> Thank you, >> Tim >> >> >> -- >> Tim A. Thompson >> Metadata Librarian (Spanish/Portuguese Specialty) >> Princeton University Library >> >

⚡Generated with XQuery