显示简单 XML php

发布于 2024-10-08 20:51:59 字数 667 浏览 0 评论 0原文

我正在寻找与此等效的内容:

$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');

问候

I am looking for something equivalent to this:

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

now this print allows to display whats in the xml list into a table.

But my with my simple xml (combined with $dom for formatting) i have no idea how to display this. Although this generates the proper output i wish into the xml how do i display the xml below? Something similar to a print or?

The purpose is to display the values of the xml into a table.

$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');

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑凤梨 2024-10-15 20:51:59

您不需要对 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

有关从 SimpleXMLElement 检索 DOMElement(及其 DOMDocument)的更多信息,可以在 dom_import_simplexml()

You don't need to stringify (technical term!) the SimpleXMLElement to load it into a DOMDocument, in fact that's a terrible idea (though, you're forgiven).

$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

More info about retrieving a DOMElement (and its DOMDocument) from a SimpleXMLElement can be found in the docs for dom_import_simplexml().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文