PHP错误:DOMDocument :: loadXML()[domdocument.loadxml]:起始标签应为'<'在实体中找不到 [英] PHP Error: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity
问题描述
请检查此波纹管程序。
Please check this bellow program.
:: Program ::
::Program::
<?php
$xml='
<books>
<book>
<name>Java complete reference</name>
<cost>256</cost>
</book>
<book>
<name>Head First PHP and Mysql</name>
<cost>389</cost>
</book>
</books>';
$dom=new DOMDocument();
$dom->loadXML($xml);
foreach ($dom->getElementsByTagName('book') as $book)
{
foreach($book->getElementsByTagName('name') as $name)
{
$names[]=$name->nodeValue;
}
foreach($book->getElementsByTagName('cost') as $cost)
{
$costs[]=$cost->nodeValue;
}
}
print_r($names);
?>
显示错误:
DOMDocument :: loadXML()[domdocument.loadxml]:应为开始标签,在实体中找不到'<<'
DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity
这是正确的方法吗?
如果正确,是否有任何方法可以在不更改此&的情况下获得正确的结果; lt;
到<
和& gt;
到>
?
If it is correct, Is there any way to get the proper result without changing this <
to <
and >
to >
?
推荐答案
您不应该将字符实体用于 <
和>
实际上是表示XML的字符串中的XML标签。应当是这样:
You should not be using character entities for <
and >
on things that are actually XML tags in the string that represents your XML. It should be this:
$xml='
<books>
<book>
...
这样做,警告就消失了。
Do that and the warning goes away.
您只需在<
和>
中使用字符实体是实际数据的一部分,而不是分隔XML标签。
You only need to use character entities for <
and >
when they are part of the actual data rather than delimiting an XML tag.
这篇关于PHP错误:DOMDocument :: loadXML()[domdocument.loadxml]:起始标签应为'<'在实体中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!