PHP getDocNamespaces() လုပ်ဆောင်ချက်
ဥပမာ
XML စာရွက်စာတမ်း၏ အမြစ်တွင် ဖော်ပြထားသော namespace များကို ပြန်ပေးပါ။
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3schools.com/ns">
<c:car id="1">Volvo</c:car>
<c:car id="2">BMW</c:car>
<c:car id="3">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces();
print_r($ns);
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
getDocNamespaces() လုပ်ဆောင်ချက်သည် XML စာရွက်စာတမ်းတစ်ခုတွင် ကြေညာထားသော namespaces ကို ပြန်ပေးသည်။
အထားအသို
SimpleXMLElement::getDocNamespaces(recursive, from_root)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
recursive | Optional. Specifies a Boolean value. If TRUE, all namespaces declared in document are returned. If FALSE, only namespaces declared in root node is returned. Default is FALSE |
from_root | Optional. Specifies a Boolean value. TRUE checks namespaces from the root of the XML document. FALSE checks namespaces under a child node. Default is TRUE |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ၎င်းတို့၏ဆက်စပ် URI များနှင့်အတူ namespace အမည်များ၏ array တစ်ခု |
---|---|
PHP ဗားရှင်း- | 5.1.2+ |
PHP Changelog- | PHP 5.4- from_root ကန့်သတ်ဘောင် ကို ထည့်ထားသည် ။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
XML စာရွက်စာတမ်းတွင် ဖော်ပြထားသော namespace အားလုံးကို ပြန်ပေးပါ။
<?php
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<cars xmlns:c="http://w3schools.com/ns">
<c:car id="1">Volvo</c:car>
<c:car id="2">BMW</c:car>
<c:car id="3" a:country="Sweden" xmlns:a="http://w3schools.com/country">Saab</c:car>
</cars>
XML;
$sxe=new SimpleXMLElement($xml);
$ns=$sxe->getDocNamespaces(TRUE);
var_dump($ns);
?>
❮ PHP SimpleXML အကိုးအကား