我有一个xml如下:
<stream:features> <readreceipts></readreceipts> <groups_v2></groups_v2> <privacy></privacy> <presence></presence> </stream:features>
<auth mechanism="WAUTH-2" user="919414556709">91941455670925 TnoXp8R!1449658547</auth>
<start from="s.whatsapp.net"></start>
<stream:features></stream:features>
<challenge>"3Yw`_}.)</challenge>
<response>Is?F5Q:Zl[uY,!Ac</response>
<success t="1449658699" props="4" kind="free" status="active" creation="1449574308" expiration="1481110308">, `gy~Z5u?bK</success>
<presence name="SG"></presence>
<message to="919414556709@s.whatsapp.net" type="text" id="A0ddU1vfrD1K0" t="1449658548" notify="SG"> <body></body> </message>
<ib from="s.whatsapp.net"> <offline count="0"></offline> </ib>
<presence from="919414556709@s.whatsapp.net"></presence>
<ack from="919414556709@s.whatsapp.net" class="message" id="A0ddU1vfrD1K0" t="1449658700"></ack>
<br />
我希望得到我使用代码的所有标签:
$xml = simplexml_load_string( $res);
foreach( $xml->xpath( '//widget') as $el) {
$attributes = $el->attributes();
$children = $el->children(); // OR: $el->xpath('title'); if children vary
echo $attributes['id'] . ' ' . $children[0] . "\n";
}
但收到错误:
<b>Warning</b>: simplexml_load_string(): namespace error : Namespace prefix stream on features is not defined in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Warning</b>: simplexml_load_string(): <stream:features> <readreceipts></readreceipts> <groups_v2></groups_v2> <pri in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Warning</b>: simplexml_load_string(): ^ in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Warning</b>: simplexml_load_string(): Entity: line 2: parser error : Extra content at the end of the document in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Warning</b>: simplexml_load_string(): <auth mechanism="WAUTH-2" user="919414556709">91941455670925 TnoXp8R!14496585 in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Warning</b>: simplexml_load_string(): ^ in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>54</b><br />
<br />
<b>Fatal error</b>: Call to a member function xpath() on boolean in <b>C:\wampp\htdocs\Chat-API-master\examples\test.php</b> on line <b>55</b><br />
如何解决此错误