Puzzling XQuery result
Saturday, 9 April 2011 · 8 messages
CG
Dear Meredith,
Quoted text · Meredith Gregory · 2 lines
> for $rcrd in collection( 'Squibble' )//record where $rcrd/*[1] = > <contentChannel><String>email</String></contentChannel> return $rcrd
In your query, the XML snippets <contentChannel>... is "atomized" (i.e., converted to a string), before it is compared to the atomized result of the first argument. If you want to the equality of your XML fragment, you might want to try the deep-equals() function. A query could look sth like this:
let $xml := <contentChannel><String>email</String></contentChannel>
for $rcrd in collection( 'Squibble' )//record
where deep-equals($rcrd/*[1], $xml)
return $rcrdHope this helps,
Christian
CG
Quoted text · Meredith Gregory · 1 line
> P.S. To further demonstrate my cluelessness...
;)
Quoted text · Meredith Gregory · 2 lines
> for $rcrd in collection( 'Squibble' )//record let $k := $rcrd/*[1] where > node-name( $k ) = contentChannel return $rcrd
This might help you out:
for $rcrd in collection( 'Squibble' )//record
where name( $rcrd/*[1] ) = "contentChannel"
return $rcrdYou could also try
collection( 'Squibble' )//record[contentChannel]
Christian
CG
Quoted text · Meredith Gregory · 1 line
> Thanks! The GUI says it's never heard of "deep-equals". Any suggestions?
Sorry, it was deep-equal; an example: deep-equals('a','b')
CG
Christian Grün9 Apr 2011 04:00 #
Quoted text · Christian Grün · 1 line
> Sorry, it was deep-equal; an example: deep-equals('a','b')
(Hopefully) last correction: deep-equal('a','b')
MG
Meredith Gregory9 Apr 2011 05:44 #
Dear BaseXers,
i've got a result from an XQuery that i don't understand and am looking for insight and guidance. i've got a collection called 'Squibble' with three documents in it. They are listed below. The query
for $rcrd in collection( 'Squibble' )//record where $rcrd/*[1] =
<contentChannel><String>email</String></contentChannel> return $rcrdreturns record elements from the first *two* documents. This is surprising to me because the first child of the first record element in the first document is <contactMeUsing>...</contactMeUsing>, not
<contentChannel>...</contentChannel>.
i was expecting it to return just the record element from the second document.
i confess, i don't know anything about XQuery. So, it could be that i don't understand how the where clause is supposed to work. Any clues would be most appreciated.
i'm running my tests using
- BaseX 6.6
- on Mac OS X 10.6.7
Best wishes,
--greg
<?xml version="1.0" encoding="UTF-8"?>
<record>
<contactMeUsing>
<String>email</String>
</contactMeUsing>
<String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class&quot;:&quot;string&quot;,&quot;$&quot;:&quot;for
the win Mikail.Mauz at gmail.com
&quot;},&quot;_-outer&quot;:{&quot;@class
&quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String>
</record>
<?xml version="1.0" encoding="UTF-8"?>
<record>
<contentChannel>
<String>email</String>
</contentChannel>
<String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class&quot;:&quot;string&quot;,&quot;$&quot;:&quot;for
the get Donald.Duque at yahoo.com
&quot;},&quot;_-outer&quot;:{&quot;@class
&quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String>
</record>
<?xml version="1.0" encoding="UTF-8"?>
<record>
<phone>
<var>cell</var>
</phone>
<String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class
&quot;:&quot;string&quot;,&quot;$&quot;:&quot;2xx.6xx.3xxx&quot;},&quot;_-outer&quot;:{&quot;@class
&quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String>
</record>--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW
Seattle, WA 98136
+1 206.650.3740
http://biosimilarity.blogspot.com
MG
Meredith Gregory9 Apr 2011 05:56 #
P.S. To further demonstrate my cluelessness...
for $rcrd in collection( 'Squibble' )//record let $k := $rcrd/*[1] where
node-name( $k ) = contentChannel return $rcrdreturns nothing -- while
for $rcrd in collection( 'Squibble' )//record let $k := $rcrd/*[1] return
node-name( $k )returns
contactMeUsing contentChannel phone
i find this mildly surprising.
On Fri, Apr 8, 2011 at 6:44 PM, Meredith Gregory
<lgreg.meredith at gmail.com>wrote:
Quoted text · Meredith Gregory · 78 lines
> Dear BaseXers, > > i've got a result from an XQuery that i don't understand and am looking for > insight and guidance. i've got a collection called 'Squibble' with three > documents in it. They are listed below. The query > > for $rcrd in collection( 'Squibble' )//record where $rcrd/*[1] = > <contentChannel><String>email</String></contentChannel> return $rcrd > > returns record elements from the first *two* documents. This is surprising > to me because the first child of the first record element in the first > document is <contactMeUsing>...</contactMeUsing>, not > <contentChannel>...</contentChannel>. > > i was expecting it to return just the record element from the second > document. > > i confess, i don't know anything about XQuery. So, it could be that i don't > understand how the where clause is supposed to work. Any clues would be most > appreciated. > > i'm running my tests using > > - BaseX 6.6 > - on Mac OS X 10.6.7 > > > Best wishes, > > --greg > > <?xml version="1.0" encoding="UTF-8"?> > <record> > <contactMeUsing> > <String>email</String> > </contactMeUsing> > > <String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class&quot;:&quot;string&quot;,&quot;$&quot;:&quot;for > the win Mikail.Mauz at gmail.com > &quot;},&quot;_-outer&quot;:{&quot;@class > &quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String> > </record> > > <?xml version="1.0" encoding="UTF-8"?> > <record> > <contentChannel> > <String>email</String> > </contentChannel> > > <String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class&quot;:&quot;string&quot;,&quot;$&quot;:&quot;for > the get Donald.Duque at yahoo.com > &quot;},&quot;_-outer&quot;:{&quot;@class > &quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String> > </record> > > <?xml version="1.0" encoding="UTF-8"?> > <record> > <phone> > <var>cell</var> > </phone> > > <String>{&quot;com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground&quot;:{&quot;v&quot;:{&quot;@class > &quot;:&quot;string&quot;,&quot;$&quot;:&quot;2xx.6xx.3xxx&quot;},&quot;_-outer&quot;:{&quot;@class > &quot;:&quot;com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$&quot;}}}</String> > </record> > > -- > L.G. Meredith > Managing Partner > Biosimilarity LLC > 7329 39th Ave SW > Seattle, WA 98136 > > +1 206.650.3740 > > http://biosimilarity.blogspot.com > >
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW
Seattle, WA 98136
+1 206.650.3740
http://biosimilarity.blogspot.com
MG
Dear Christian,
Thanks! The GUI says it's never heard of "deep-equals". Any suggestions?
Best wishes,
--greg
On Fri, Apr 8, 2011 at 6:56 PM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 19 lines
> Dear Meredith, > > > for $rcrd in collection( 'Squibble' )//record where $rcrd/*[1] = > > <contentChannel><String>email</String></contentChannel> return $rcrd > > In your query, the XML snippets <contentChannel>... is "atomized" > (i.e., converted to a string), before it is compared to the atomized > result of the first argument. If you want to the equality of your XML > fragment, you might want to try the deep-equals() function. A query > could look sth like this: > > let $xml := <contentChannel><String>email</String></contentChannel> > for $rcrd in collection( 'Squibble' )//record > where deep-equals($rcrd/*[1], $xml) > return $rcrd > > Hope this helps, > Christian >
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW
Seattle, WA 98136
+1 206.650.3740
http://biosimilarity.blogspot.com
MG
Dear Christian,
Thanks for the prompt responses! The last one did the trick. It's now performing as expected. Cheers!
Best wishes,
--greg
On Fri, Apr 8, 2011 at 7:00 PM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 4 lines
> > Sorry, it was deep-equal; an example: deep-equals('a','b') > > (Hopefully) last correction: deep-equal('a','b') >
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW
Seattle, WA 98136
+1 206.650.3740
http://biosimilarity.blogspot.com
Written for BaseX 6.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery