我有以下XML文件
<?xml version="1.0" encoding="UTF-8"?>
<newsItem>
<contentSet>
<inlineXML contenttype="application/xhtml+xml">
<html xmlns="http://www.w3.org/1999/xhtml">
<div>
<h1>St. Augustine Gold and Copper Limited: Update on Recent Corporate Developments</h1>
</div>
</html>
</inlineXML>
</contentSet>
</newsItem>
我希望使用以下代码获取值,没有问题
if (file_exists('example.newsml')) {
$xml = simplexml_load_file('example.newsml');
$html= (string) $xml->{'contentSet'}->{'inlineXML'}->{'html'}->{'div'}->{'h1'};
echo $html;
} else {
exit('Failed to open test.xml.');
}
我试图从节点获取html,但结果为空。
$content = (string) $xml->{'contentSet'}->{'inlineXML'}->{'html'};
echo $content;
有什么建议吗?
答案 0 :(得分:0)
只需将节点另存为XML
echo $xml->contentSet->inlineXML->html->saveXml();
<html xmlns="http://www.w3.org/1999/xhtml">
<div>
<h1>St. Augustine Gold and Copper Limited: Update on Recent Corporate Developments</h1>
</div>
</html>