XQuery ဥပမာ
ဥပမာတစ်ခုကြည့်ခြင်းဖြင့် အခြေခံ XQuery အချို့ကို လေ့လာကြပါစို့။
XML နမူနာစာရွက်စာတမ်း
အောက်ဖော်ပြပါ နမူနာများတွင် အောက်ပါ XML စာရွက်စာတမ်းကို ကျွန်ုပ်တို့ အသုံးပြုပါမည်။
"books.xml"-
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
သင့်ဘရောက်ဆာရှိ "books.xml" ဖိုင်ကို ကြည့်ရှုပါ ။
"books.xml" မှ Nodes ကိုမည်သို့ရွေးချယ်မည်နည်း။
လုပ်ဆောင်ချက်များ
XQuery သည် XML စာရွက်စာတမ်းများမှဒေတာကိုထုတ်ယူရန်လုပ်ဆောင်ချက်များကိုအသုံးပြုသည်။
"books.xml" ဖိုင်ကိုဖွင့်ရန် doc() လုပ်ဆောင်ချက်ကို အသုံးပြုသည်-
doc("books.xml")
လမ်းကြောင်းအသုံးအနှုန်းများ
XQuery သည် XML စာရွက်စာတမ်းရှိ ဒြပ်စင်များမှတဆင့် သွားလာရန် လမ်းကြောင်းအသုံးအနှုန်းများကို အသုံးပြုသည်။
"books.xml" ဖိုင်ရှိ ခေါင်းစဉ်ဒြပ်စင်အားလုံးကို ရွေးချယ်ရန် အောက်ပါလမ်းကြောင်းအသုံးအနှုန်းကို အသုံးပြုသည်-
doc("books.xml")/bookstore/book/title
(/bookstore သည် စာအုပ်ဆိုင်ဒြပ်စင်ကို ရွေးသည်၊ /book သည် စာအုပ်ဆိုင်ဒြပ်စင်အောက်ရှိ စာအုပ်ဒြပ်စင်အားလုံးကို ရွေးသည်၊ /title သည် စာအုပ်ဒြပ်စင်တစ်ခုစီအောက်ရှိ ခေါင်းစဉ်အစိတ်အပိုင်းအားလုံးကို ရွေးသည်)
အထက်ဖော်ပြပါ XQuery သည် အောက်ပါတို့ကို ထုတ်ယူပါမည်။
<title lang="en">Everyday Italian</title>
<title lang="en">Harry Potter</title>
<title lang="en">XQuery Kick Start</title>
<title lang="en">Learning XML</title>
ခန့်မှန်းချက်များ
XQuery သည် XML စာရွက်စာတမ်းများမှ ထုတ်ယူထားသော ဒေတာကို ကန့်သတ်ရန် ကိန်းဂဏန်းများကို အသုံးပြုသည်။
စျေးနှုန်း 30 ထက်နည်းသော တန်ဖိုးရှိသော စာအုပ်ဆိုင်ဒြပ်စင်အောက်ရှိ စာအုပ်ဒြပ်စင်များအောက်ရှိ စာအုပ်ဒြပ်စင်အားလုံးကို ရွေးချယ်ရန် အောက်ပါကြိုတင်ဖော်ပြချက်ကို အသုံးပြုသည်-
doc("books.xml")/bookstore/book[price<30]
အထက်ဖော်ပြပါ XQuery သည် အောက်ပါတို့ကို ထုတ်ယူပါမည်။
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>