<?xml version="1.0" encoding="UTF-8"?><tv><channel id="Nick Jr.">
<display-name lang="en">Nick Jr. MX</display-name><icon src="Nick Jr..png" />
<url>http://www.my.tv</url>
</channel><channel id="The NFL Network ">
<display-name lang="en">The NFL Network </display-name><icon src="The NFL Network .png" />
<url>http://www.my.tv</url>
</channel><channel id="ESPN">
<display-name lang="en">ESPN</display-name><icon src="ESPN.png" />
<url>http://www.my.tv</url>
</channel><channel id="ESPN News">
<display-name lang="en">ESPN News</display-name><icon src="ESPN News.png" />
<url>http://www.my.tv</url>
</channel><channel id="ESPNU">
<display-name lang="en">ESPNU</display-name><icon src="ESPNU.png" />
<url>http://www.my.tv</url>
</channel><channel id="ESPN2">
<display-name lang="en">ESPN2</display-name><icon src="ESPN2.png" />
<url>http://www.my.tv</url>
</channel><channel id="The NFL Network">
<display-name lang="en">The NFL Network</display-name><icon src="The NFL Network.png" />
<url>http://www.my.tv</url>
</channel><channel id="MLB Network">
<display-name lang="en">MLB Network</display-name><icon src="MLB Network.png" />
<url>http://www.my.tv</url>
</channel><channel id="MavTV">
<display-name lang="en">MavTV</display-name><icon src="MavTV.png" />
<url>http://www.my.tv</url>
</channel>
</tv>
这是xml。通常这将从网址获取。比如说 url ='http://hello.com/myxml.xml
我想创建一个修复此xml的PHP脚本并将修复的xml重写到我的服务器(localhost)
并帮忙?
答案 0 :(得分:1)
使用SimpleXML库分析,并将固定的xml重写到您的服务器
答案 1 :(得分:0)
XML没有格式错误。这很好。这里甚至没有通知/警告。
libxml_use_internal_errors();
$document = new DOMDocument();
$document->loadXml($xml);
var_dump(libxml_get_errors());
输出:
array(0) {
}
我想你可能想要重新格式化XML。你可以用DOM做到这一点。
$document = new DOMDocument();
$document->preserveWhiteSpace = FALSE;
$document->formatOutput = TRUE;
$document->loadXml($xml);
echo $document->saveXml();
输出:
<?xml version="1.0" encoding="UTF-8"?>
<tv>
<channel id="Nick Jr.">
<display-name lang="en">Nick Jr. MX</display-name>
<icon src="Nick Jr..png"/>
<url>http://www.my.tv</url>
</channel>
<channel id="The NFL Network ">
<display-name lang="en">The NFL Network </display-name>
<icon src="The NFL Network .png"/>
<url>http://www.my.tv</url>
</channel>
...