显示Simple XML php

时间:2010-12-18 18:15:31

标签: php xml simplexml

我正在寻找与此相当的东西:

$e= xmlwriter_open_uri("test.xml");
....
print htmlentities(xmlwriter_output_memory($e));

现在这个打印允许在xml列表中显示表格中的内容。

但我的简单xml(结合$ dom格式化)我不知道如何显示它。虽然这会生成正确的输出,我希望进入xml如何在下面显示xml?类似于印刷品的东西或?

目的是将xml的值显示在表中。

$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

$xml = new SimpleXMLElement('<test></test>');       
    $one= $xml->addChild('enemy', 'yes');           
    $two= $xml->addChild('friend', 'maybe');           

$dom->loadXML($xml->asXML());
$dom->save('test.xml');

此致

1 个答案:

答案 0 :(得分:1)

您不需要对{{1>}进行字符串化(技术术语!)以将其加载到SimpleXMLElement中,事实上这是一个可怕的想法(尽管如此,你'原谅)。

DOMDocument

有关从$xml = new SimpleXMLElement('<test></test>'); $one= $xml->addChild('enemy', 'yes'); $two= $xml->addChild('friend', 'maybe'); // Get the DOMDocument associated with this XML $dom = dom_import_simplexml($xml)->ownerDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; echo $dom->saveXML(); // or echo htmlentities($dom->saveXML()) if you really must 检索DOMElement(及其DOMDocument)的更多信息,请参阅dom_import_simplexml()的文档。