एक्सएमएल और XPath
XPath क्या है?
XPath XSLT मानक में एक प्रमुख तत्व है।
XPath का उपयोग XML दस्तावेज़ में तत्वों और विशेषताओं के माध्यम से नेविगेट करने के लिए किया जा सकता है।
|
XPath पथ अभिव्यक्तियाँ
XPath किसी XML दस्तावेज़ में नोड्स या नोड-सेट का चयन करने के लिए पथ अभिव्यक्तियों का उपयोग करता है। जब आप पारंपरिक कंप्यूटर फ़ाइल सिस्टम के साथ काम करते हैं तो ये पथ अभिव्यक्तियाँ आपके द्वारा देखे जाने वाले भावों के समान दिखती हैं।
XPath अभिव्यक्तियों का उपयोग जावास्क्रिप्ट, जावा, एक्सएमएल स्कीमा, पीएचपी, पायथन, सी और सी ++, और कई अन्य भाषाओं में किया जा सकता है।
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 ट्यूटोरियल में XPath के बारे में बहुत कुछ जानेंगे ।