<?php
$dom = new DOMDocument();
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<root>
<item id="i1">sdfds</item>
<item id="i2">sxfds</item>
</root>
XML;
$dom->preserveWhiteSpace = false;
$dom->loadxml($xml);
//$dom->load("getId.xml");
$root = $dom->getElementsByTagName('root')->item(0);
$childs = $root->childNodes;
for($i=0; $i<$childs->length;$i++){
$item = $childs->item($i);
$item->setIdAttribute('id', true);
}
echo $dom->getElementById("i1")->tagName;
echo $dom->getElementById("i2")->tagName;
?>
我用load()方法可以读成功,但是用loadxml方法却报错,请问什么原因?
侃侃尔雅