Individual docs from collection
Saturday, 8 September 2012 · 7 messages · last reply 9 Sep 2012
S
sateesh8 Sep 2012 12:27 #
Hi Basex,
I have created a collection with 10k xml files and now on that collection I want to write query on few xml's only .could you please suggest how this functionality is achieved.
Thanks & Regards
Sateesh.A
HV
Huib Verweij8 Sep 2012 13:36 #
Hi Sateesh,
Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven:
Quoted text · sateesh · 5 lines
> > I have created a collection with 10k xml files and now on that collection I want to write query on few xml's only .could you please suggest how this functionality is achieved. > > Thanks & Regards > Sateesh.A
what I always do is use an XQuery that selects the documents by some criterium, then process them further, e.g.
for $doc in collection('foo')/rootelement[@type='selectedtype']
let $name := $doc/name (: f.i.: )
etc...or if you want you can assign the docs to a variable (handy if you want to process the set multiple times f.i.):
let $docs := collection('foo')/rootelement[@type='selectedtype']Hartelijke groet,
Huib Verweij
S
sateesh8 Sep 2012 14:12 #
Hi Huib Verweij,
Thanks for the reply,but I have a small problem with your approach I don't have a criteria with which I can select my required docs with in collection,I get my required doc names from outside and with those names only I need to search the collection.
Thanks & regards
Sateesh.A
Quoted text · Huib Verweij · 25 lines
-----Original Message----- From: Huib Verweij [mailto:hhv at home.nl] Sent: Saturday, September 08, 2012 5:06 PM To: sateesh Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Individual docs from collection Hi Sateesh, Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven: > > I have created a collection with 10k xml files and now on that collection I want to write query on few xml's only .could you please suggest how this functionality is achieved. > > Thanks & Regards > Sateesh.A what I always do is use an XQuery that selects the documents by some criterium, then process them further, e.g. for $doc in collection('foo')/rootelement[@type='selectedtype'] let $name := $doc/name (: f.i.: ) etc... or if you want you can assign the docs to a variable (handy if you want to process the set multiple times f.i.): let $docs := collection('foo')/rootelement[@type='selectedtype'] Hartelijke groet, Huib Verweij
BC
Ben Companjen8 Sep 2012 14:47 #
Hi Sateesh,
If I understand correctly, the selection criteria are (1) that the name of the document is in a list of document names that you have and (2) that these documents are in a specific collection (in case not all documents in the list are in the collection, you want to check this too).
If your list of document names is also in XML, e.g.
<list>
<doc>docname1.xml</doc>
<doc>docname2.xml</doc>
...
</list>
you could use:
let $doclist := document {
<list>
<doc>docname1.xml</doc>
<doc>docname2.xml</doc>
</list>
}
for $docname in $doclist/list/doc/text() intersect uri-collection("collection")
let $doc := doc($docname)
(: do something :)
return concat("processing...",$docname)Perhaps you need to make sure that the document names are of type xs:anyURI instead of string, but I suppose you can figure that out :)
Is that what you were thinking of?
Ben
Quoted text · sateesh · 52 lines
On 8 September 2012 14:12, sateesh <sateesh at intense.in> wrote: > Hi Huib Verweij, > > Thanks for the reply,but I have a small problem with your approach I don't > have a criteria with which I can select my required docs with in > collection,I get my required doc names from outside and with those names > only I need to search the collection. > > Thanks & regards > Sateesh.A > > -----Original Message----- > From: Huib Verweij [mailto:hhv at home.nl] > Sent: Saturday, September 08, 2012 5:06 PM > To: sateesh > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Individual docs from collection > > Hi Sateesh, > > Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven: > >> >> I have created a collection with 10k xml files and now on that collection > I want to write query on few xml's only .could you please suggest how this > functionality is achieved. >> >> Thanks & Regards >> Sateesh.A > > what I always do is use an XQuery that selects the documents by some > criterium, then process them further, e.g. > > for $doc in collection('foo')/rootelement[@type='selectedtype'] > let $name := $doc/name (: f.i.: ) > etc... > > or if you want you can assign the docs to a variable (handy if you want to > process the set multiple times f.i.): > > let $docs := collection('foo')/rootelement[@type='selectedtype'] > > Hartelijke groet, > Huib Verweij > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
S
sateesh8 Sep 2012 15:20 #
Hi Ben,
Iam looking for the same one ,but when I execute the query iam getting following exception InterSect expression: node() expected,xs:anyuri found.
I think u hinted something in ur last point but iam not able to understand that.Could u please help me in resolving the above exception.
Thanks & regards
Sateesh.A
Quoted text · Ben Companjen · 85 lines
-----Original Message----- From: Ben Companjen [mailto:bencompanjen at gmail.com] Sent: Saturday, September 08, 2012 6:17 PM To: sateesh Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Individual docs from collection Hi Sateesh, If I understand correctly, the selection criteria are (1) that the name of the document is in a list of document names that you have and (2) that these documents are in a specific collection (in case not all documents in the list are in the collection, you want to check this too). If your list of document names is also in XML, e.g. <list> <doc>docname1.xml</doc> <doc>docname2.xml</doc> ... </list> you could use: let $doclist := document { <list> <doc>docname1.xml</doc> <doc>docname2.xml</doc> </list> } for $docname in $doclist/list/doc/text() intersect uri-collection("collection") let $doc := doc($docname) (: do something :) return concat("processing...",$docname) Perhaps you need to make sure that the document names are of type xs:anyURI instead of string, but I suppose you can figure that out :) Is that what you were thinking of? Ben On 8 September 2012 14:12, sateesh <sateesh at intense.in> wrote: > Hi Huib Verweij, > > Thanks for the reply,but I have a small problem with your approach I don't > have a criteria with which I can select my required docs with in > collection,I get my required doc names from outside and with those names > only I need to search the collection. > > Thanks & regards > Sateesh.A > > -----Original Message----- > From: Huib Verweij [mailto:hhv at home.nl] > Sent: Saturday, September 08, 2012 5:06 PM > To: sateesh > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Individual docs from collection > > Hi Sateesh, > > Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven: > >> >> I have created a collection with 10k xml files and now on that collection > I want to write query on few xml's only .could you please suggest how this > functionality is achieved. >> >> Thanks & Regards >> Sateesh.A > > what I always do is use an XQuery that selects the documents by some > criterium, then process them further, e.g. > > for $doc in collection('foo')/rootelement[@type='selectedtype'] > let $name := $doc/name (: f.i.: ) > etc... > > or if you want you can assign the docs to a variable (handy if you want to > process the set multiple times f.i.): > > let $docs := collection('foo')/rootelement[@type='selectedtype'] > > Hartelijke groet, > Huib Verweij > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
CG
Thanks everyone for the feedback. Here’s one more solution:
let $dbname := 'db'
let $doc := (
'doc1.xml',
'doc2.xml'
) ! ($dbname || '/' || .)
for $doc in collection($dbname)[document-uri() = $doc]
return 'do something'The $doc variable contains the list of documents, which will be prefixed with the name of the database ($dbname). In the subsequent loop, all documents will be skipped that don't equal the requested document uri.
Hope this helps,
Christian
Quoted text · Ben Companjen · 91 lines
On Sat, Sep 8, 2012 at 2:47 PM, Ben Companjen <bencompanjen at gmail.com> wrote: > Hi Sateesh, > > If I understand correctly, the selection criteria are (1) that the > name of the document is in a list of document names that you have and > (2) that these documents are in a specific collection (in case not all > documents in the list are in the collection, you want to check this > too). > > If your list of document names is also in XML, e.g. > <list> > <doc>docname1.xml</doc> > <doc>docname2.xml</doc> > ... > </list> > you could use: > > let $doclist := document { > <list> > <doc>docname1.xml</doc> > <doc>docname2.xml</doc> > </list> > } > for $docname in $doclist/list/doc/text() intersect uri-collection("collection") > let $doc := doc($docname) > (: do something :) > return concat("processing...",$docname) > > Perhaps you need to make sure that the document names are of type > xs:anyURI instead of string, but I suppose you can figure that out :) > > Is that what you were thinking of? > > Ben > > On 8 September 2012 14:12, sateesh <sateesh at intense.in> wrote: >> Hi Huib Verweij, >> >> Thanks for the reply,but I have a small problem with your approach I don't >> have a criteria with which I can select my required docs with in >> collection,I get my required doc names from outside and with those names >> only I need to search the collection. >> >> Thanks & regards >> Sateesh.A >> >> -----Original Message----- >> From: Huib Verweij [mailto:hhv at home.nl] >> Sent: Saturday, September 08, 2012 5:06 PM >> To: sateesh >> Cc: basex-talk at mailman.uni-konstanz.de >> Subject: Re: [basex-talk] Individual docs from collection >> >> Hi Sateesh, >> >> Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven: >> >>> >>> I have created a collection with 10k xml files and now on that collection >> I want to write query on few xml's only .could you please suggest how this >> functionality is achieved. >>> >>> Thanks & Regards >>> Sateesh.A >> >> what I always do is use an XQuery that selects the documents by some >> criterium, then process them further, e.g. >> >> for $doc in collection('foo')/rootelement[@type='selectedtype'] >> let $name := $doc/name (: f.i.: ) >> etc... >> >> or if you want you can assign the docs to a variable (handy if you want to >> process the set multiple times f.i.): >> >> let $docs := collection('foo')/rootelement[@type='selectedtype'] >> >> Hartelijke groet, >> Huib Verweij >> >> >> >> >> _______________________________________________ >> 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
SA
Sateesh A.9 Sep 2012 13:20 #
Hi Christian,
Thank u so much for the solution its working.
Thanks & Regards
Sateesh.A
Quoted text · Christian Grün · 112 lines
Christian Grün writes: > Thanks everyone for the feedback. Here�s one more solution: > > let $dbname := 'db' > let $doc := ( > 'doc1.xml', > 'doc2.xml' > ) ! ($dbname || '/' || .) > for $doc in collection($dbname)[document-uri() = $doc] > return 'do something' > > The $doc variable contains the list of documents, which will be > prefixed with the name of the database ($dbname). In the subsequent > loop, all documents will be skipped that don't equal the requested > document uri. > > Hope this helps, > Christian > ___________________________ > > On Sat, Sep 8, 2012 at 2:47 PM, Ben Companjen <bencompanjen at gmail.com> wrote: >> Hi Sateesh, >> >> If I understand correctly, the selection criteria are (1) that the >> name of the document is in a list of document names that you have and >> (2) that these documents are in a specific collection (in case not all >> documents in the list are in the collection, you want to check this >> too). >> >> If your list of document names is also in XML, e.g. >> <list> >> <doc>docname1.xml</doc> >> <doc>docname2.xml</doc> >> ... >> </list> >> you could use: >> >> let $doclist := document { >> <list> >> <doc>docname1.xml</doc> >> <doc>docname2.xml</doc> >> </list> >> } >> for $docname in $doclist/list/doc/text() intersect uri-collection("collection") >> let $doc := doc($docname) >> (: do something :) >> return concat("processing...",$docname) >> >> Perhaps you need to make sure that the document names are of type >> xs:anyURI instead of string, but I suppose you can figure that out :) >> >> Is that what you were thinking of? >> >> Ben >> >> On 8 September 2012 14:12, sateesh <sateesh at intense.in> wrote: >>> Hi Huib Verweij, >>> >>> Thanks for the reply,but I have a small problem with your approach I don't >>> have a criteria with which I can select my required docs with in >>> collection,I get my required doc names from outside and with those names >>> only I need to search the collection. >>> >>> Thanks & regards >>> Sateesh.A >>> >>> -----Original Message----- >>> From: Huib Verweij [mailto:hhv at home.nl] >>> Sent: Saturday, September 08, 2012 5:06 PM >>> To: sateesh >>> Cc: basex-talk at mailman.uni-konstanz.de >>> Subject: Re: [basex-talk] Individual docs from collection >>> >>> Hi Sateesh, >>> >>> Op 8 sep. 2012, om 12:27 heeft sateesh het volgende geschreven: >>> >>>> >>>> I have created a collection with 10k xml files and now on that collection >>> I want to write query on few xml's only .could you please suggest how this >>> functionality is achieved. >>>> >>>> Thanks & Regards >>>> Sateesh.A >>> >>> what I always do is use an XQuery that selects the documents by some >>> criterium, then process them further, e.g. >>> >>> for $doc in collection('foo')/rootelement[@type='selectedtype'] >>> let $name := $doc/name (: f.i.: ) >>> etc... >>> >>> or if you want you can assign the docs to a variable (handy if you want to >>> process the set multiple times f.i.): >>> >>> let $docs := collection('foo')/rootelement[@type='selectedtype'] >>> >>> Hartelijke groet, >>> Huib Verweij >>> >>> >>> >>> >>> _______________________________________________ >>> 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 >
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery