Php 检索xml数据
我想从xml文件中检索数据,我需要回显产品的属性值 data.xml文件----Php 检索xml数据,php,xml,Php,Xml,我想从xml文件中检索数据,我需要回显产品的属性值 data.xml文件---- 使用getAttribute: $id = $node->getAttribute("id"); echo $id; 您可能还需要参考以了解所需的其他功能;) 我从未听说过getElementsByAttributeName(),但是如果您只想获取元素的属性,那么函数非常简单: $xml = new DomDocument(); $xmlFile = "data.xml"; $xml=
使用
getAttribute
:
$id = $node->getAttribute("id");
echo $id;
您可能还需要参考以了解所需的其他功能;) 我从未听说过
getElementsByAttributeName()
,但是如果您只想获取元素的属性,那么函数非常简单:
$xml = new DomDocument();
$xmlFile = "data.xml";
$xml= DOMDocument::load($xmlFile);
$product = $xml->getElementsByTagName("product");
foreach($product as $node) {
$id = $node->getAttribute("id");
echo $id;
}
啊,您应该引用您的XML数据:无法判断它是什么。
$id = $node->getAttribute("id");
echo $id;
$xml = new DomDocument();
$xmlFile = "data.xml";
$xml= DOMDocument::load($xmlFile);
$product = $xml->getElementsByTagName("product");
foreach($product as $node) {
$id = $node->getAttribute("id");
echo $id;
}