PHP registerXPathNamespace () الوظيفة
مثال
قم بإنشاء سياق مساحة اسم لاستعلام 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 |
تفاصيل تقنية
قيمة الإرجاع: | صواب في النجاح. خطأ في الفشل |
---|---|
إصدار PHP: | 5.1+ |
❮ مرجع PHP SimpleXML