PHP रजिस्टरXPathNamespace () फ़ंक्शन
उदाहरण
अगली XPath क्वेरी के लिए नामस्थान प्रसंग बनाएँ:
<?php
$xml=<<<XML
<book xmlns:chap="http://example.org/chapter-title">
<title>My Book</title>
<chapter id="1">
<chap:title>Chapter 1</chap:title>
<para>Donec velit. Nullam eget tellus...</para>
</chapter>
<chapter id="2">
<chap:title>Chapter 2</chap:title>
<para>Lorem ipsum dolor sit amet....</para>
</chapter>
</book>
XML;
$sxe=new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('c','http://example.org/chapter-title');
$result=$sxe->xpath('//c:title');
foreach ($result as $title)
{
echo $title . "<br>";
}
?>
परिभाषा और उपयोग
RegisterXPathNamespace() फ़ंक्शन अगले XPath क्वेरी के लिए नामस्थान संदर्भ बनाता है।
यह फ़ंक्शन तब उपयोगी होता है जब किसी XML दस्तावेज़ में नामस्थान उपसर्ग बदल दिया जाता है। registerXPathNamespace() फ़ंक्शन निर्दिष्ट नाम स्थान के लिए एक उपसर्ग बनाएगा, ताकि प्रभावित XML नोड्स को एप्लिकेशन कोड में बहुत अधिक बदलाव किए बिना एक्सेस किया जा सके।
वाक्य - विन्यास
SimpleXMLElement::registerXPathNamespace(prefix, ns)
पैरामीटर मान
Parameter | Description |
---|---|
prefix | Required. Specifies the namespace prefix to use in the XPath query for the namespace given in ns |
ns | Required. Specifies the namespace to use for the XPath query |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | सफलता पर सच। विफलता पर FALSE |
---|---|
पीएचपी संस्करण: | 5.1+ |
❮ PHP SimpleXML संदर्भ