【发布时间】:2012-04-12 23:14:42
【问题描述】:
我有这个 simplexml 脚本,用于发布从表单输入的数据。
$xml = simplexml_load_file("links.xml");
$sxe = new SimpleXMLElement($xml->asXML());
$person = $sxe->addChild("link");
$person->addChild("title", "Q: ".$x_title);
$person->addChild("url", "questions_layout.php#Question$id");
$sxe->asXML("links.xml");
当它出来时,它看起来像这样:
<link><title>Alabama State</title><url>questions_layout.php#Question37</url></link><link><title>Michigan State</title><url>questions_layout.php#Question37</url></link></pages>
但我已经尝试了找到 HERE 和 THIS AS WELL 的方法,但它们都没有正确格式化行中的 XML,因为它们应该是这样的
<link>
<title></title>
<url></url>
</link>
在第一个参考链接中,我什至将loadXML 更改为load,因为loadXML 需要一个字符串作为XML。有人可以帮我解决这个问题吗?
【问题讨论】:
标签: php formatting simplexml