我试图用 simpleXMLElement 读取 xml 版本 2 并出错。这是我的示例 xml
<?xml version="2.0"?>
<books>
<book id="978-1594489501">
<title>My books</title>
<author>Someone</author>
<publisher>publisher</publisher>
<price>14.27</price>
</book>
</books>
PHP代码:
$xml = new SimpleXMLElement('books.xml', null, true);
$attributes = $element->attributes(); // get all attributes
$children = $element->children(); // get all children
foreach($children as $key => $value){
echo $value;
}