XML နှင့် XPath
XPath ဆိုတာဘာလဲ။
XPath သည် XSLT စံနှုန်းတွင် အဓိကအစိတ်အပိုင်းတစ်ခုဖြစ်သည်။
XML စာရွက်စာတမ်းရှိ ဒြပ်စင်များနှင့် ရည်ညွှန်းချက်များကို ဖြတ်ကျော်ရန် XPath ကို အသုံးပြုနိုင်သည်။
|
XPath လမ်းကြောင်းအသုံးအနှုန်းများ
XPath သည် XML စာရွက်စာတမ်းရှိ nodes သို့မဟုတ် node-sets များကိုရွေးချယ်ရန် လမ်းကြောင်းဖော်ပြချက်များကို အသုံးပြုသည်။ သမားရိုးကျ ကွန်ပျူတာ ဖိုင်စနစ်ဖြင့် အလုပ်လုပ်သောအခါ ဤလမ်းကြောင်းဖော်ပြချက်များသည် သင်မြင်ရသည့်အသုံးအနှုန်းများနှင့် အလွန်တူပါသည်။
XPath အသုံးအနှုန်းများကို JavaScript၊ Java၊ XML Schema၊ PHP၊ Python၊ C နှင့် C++ နှင့် အခြားဘာသာစကားများစွာတွင် အသုံးပြုနိုင်သည်။
XPath ကို XSLT တွင်အသုံးပြုသည်။
XPath သည် XSLT စံနှုန်းတွင် အဓိကအစိတ်အပိုင်းတစ်ခုဖြစ်သည်။
XPath အသိပညာဖြင့် သင်သည် XSL ၏ အကျိုးကျေးဇူးများစွာကို အသုံးချနိုင်မည်ဖြစ်သည်။
XPath ဥပမာ
ကျွန်ုပ်တို့သည် အောက်ပါ 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>
အောက်ပါဇယားတွင် ကျွန်ုပ်တို့သည် XPath စကားရပ်အချို့နှင့် ဖော်ပြချက်များ၏ရလဒ်များကို ဖော်ပြထားပါသည်။
XPath Expression | Result |
---|---|
/bookstore/book[1] | Selects the first book element that is the child of the bookstore element |
/bookstore/book[last()] | Selects the last book element that is the child of the bookstore element |
/bookstore/book[last()-1] | Selects the last but one book element that is the child of the bookstore element |
/bookstore/book[position()<3] | Selects the first two book elements that are children of the bookstore element |
//title[@lang] | Selects all the title elements that have an attribute named lang |
//title[@lang='en'] | Selects all the title elements that have a "lang" attribute with a value of "en" |
/bookstore/book[price>35.00] | Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 |
/bookstore/book[price>35.00]/title | Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00 |
XPath ကျူတိုရီရယ်
ကျွန်ုပ်တို့၏ XPath Tutorial တွင် XPath အကြောင်း သင်ပိုမိုလေ့လာနိုင်မည်ဖြစ်ပါသည် ။