[xquery-talk] How can I optimize time in query

G. Ken Holman gkholman at CraneSoftwrights.com
Wed Apr 6 08:42:49 PDT 2011


Do you have the option of using XSLT?  The key facility in XSLT is 
often implemented very quickly by engines.

Sticking with XQuery, you might consider creating a sequence of 
strings being the attribute values and then checking the input file 
against the sequence of strings:

T:\ftemp>type NewDoc1.xml
<?xml version="1.0" encoding="US-ASCII"?>
<doc1>
<info id="1">
<fname>Kunal</fname>
<lname>chauhan</lname>
</info>
<info id="2">
<fname>Bhavik</fname>
<lname>Solanki</lname>
</info>
<info id="3">
<fname>Geet</fname>
<lname>Gangwar</lname>
</info>
</doc1>

T:\ftemp>type NewDoc2.xml
<?xml version="1.0" encoding="US-ASCII"?>
<Doc2>
<empinfo id="1">
<name>Kunal</name>
<dept>tech</dept>
<roll>prog</roll>
</empinfo>
<empinfo id="2xxx">
<name>Bhavik</name>
<dept>tech</dept>
<roll>prog</roll>
</empinfo>
<empinfo id="3">
<name>Geet</name>
<dept>tech</dept>
<roll>tl</roll>
</empinfo>
</Doc2>

T:\ftemp>xquery kunal.xq
<?xml version="1.0" encoding="UTF-8"?>
<fname>Kunal</fname>
<fname>Geet</fname>
T:\ftemp>type kunal.xq
let $d1 := doc("NewDoc1.xml")
let $d2attrValues := doc("NewDoc2.xml")/Doc2/empinfo/@id/string()

for $x in $d1/doc1/info where $x/@id = $d2attrValues
return $x/fname

T:\ftemp>

I hope this helps.

. . . . . . . . Ken


At 2011-04-06 17:07 +0530, Kunal Chauhan wrote:
>Hi All,
>
>I wrote one XQuery it's work but taking time I want to optimize time 
>taken by that XQuery.
>Here I explaine a brief scenario.
>There are two diff xml files. I need to check first xml file's tag's 
>attributes value and check it into second file
>If this value is same than I need to go forward for more process.
>I used for loop for it but it takes time so how can I optimize time 
>in this case.
>
>here is example
>
>First XML file
>
><?xml version="1.0" encoding="US-ASCII"?>
><doc1>
><info id="1">
><fname>Kunal</fname>
><lname>chauhan</lname>
></info>
><info id="2">
><fname>Bhavik</fname>
><lname>Solanki</lname>
></info>
><info id="3">
><fname>Geet</fname>
><lname>Gangwar</lname>
></info>
></doc1>
>
>
>Second XML file
>
><?xml version="1.0" encoding="US-ASCII"?>
><Doc2>
><empinfo id="1">
><name>Kunal</name>
><dept>tech</dept>
><roll>prog</roll>
></empinfo>
><empinfo id="2">
><name>Bhavik</name>
><dept>tech</dept>
><roll>prog</roll>
></empinfo>
><empinfo id="3">
><name>Geet</name>
><dept>tech</dept>
><roll>tl</roll>
></empinfo>
></Doc2>
>
>XQuery
>
>let $d1 := doc("D:/xbrl/NewDoc1.xml")
>let $d2 := doc("D:/xbrl/NewDoc2.xml")
>
>for $x in $d1,$y in $d2
>check ($x/doc1/info/@id = $y/Doc2/empinfo/attribute::id)   // check 
>ids of each node and if they are same than process forward
>...
>...
>..
>return $y/Doc2/empinfo/name
>
>in this example I just return name but actualyy if ids are same than 
>I need to go forward and do some more process and after that return 
>final result.
>so is there any other way, other than for loop
>
>
>Thanks & Regards,
>
>Kunal Chauhan
><mailto:mail4ck at gmail.com>mail4ck at gmail.com
>[+918655517141]
>[+919904983614]


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:gkholman at CraneSoftwrights.com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



More information about the talk mailing list