代码
<?php
$xml = <<<XML
<xml>
<body bgcolor="red">red</body>
<body bgcolor="green">green</body>
</xml>
XML;

$dom = new DomDocument();
$dom->loadXML($xml);

$xpath = new DomXpath($dom);
$nodes = $xpath->query("*[local-name()='body']", $dom->documentElement);

echo $nodes->item(0)->getAttributeNode('bgcolor')->value;
?>

 

The result:

red

相关文章:

  • 2021-06-12
  • 2021-10-01
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-06-13
相关资源
相似解决方案