[英]PHP How to read XML Child Node Value in a String using PHP?
我有一個String,它從其他服務器動態獲取其值。 字符串的值是
$string1 = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.microsoft.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AuthenticateUserResponse xmlns="http://microsoft.com/xml/namespace/2012/04">
<Authenticator>AE1001</Authenticator>
</AuthenticateUserResponse>
</soap:Body>
</soap:Envelope>';
我的問題是,通常我們使用* $ xml = simplexml_load_file(“test1.xml”); *來加載XML文件,但在我的要求中它是一個String ,我怎樣才能讀取這個String值並提取子節點及其值? 例:
<Authenticator> and its value "AE1001" ?
有沒有辦法將其放入數組? 這樣我就可以輕松打印出它的節點值了嗎?
還學習DOMDocument和XPath 。 真的值得花時間。
$doc = new DOMDocument;
$doc->loadXML($string1);
echo $doc->getElementsByTagName('Authenticator')->item(0)->nodeValue; // AE1001
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.