Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单XML元素无法解析a<;链接类型="&引用&燃气轮机;.atom文件中的字符串_Php_Xml_Parsing_Simplexml_Atom Feed - Fatal编程技术网

Php 简单XML元素无法解析a<;链接类型="&引用&燃气轮机;.atom文件中的字符串

Php 简单XML元素无法解析a<;链接类型="&引用&燃气轮机;.atom文件中的字符串,php,xml,parsing,simplexml,atom-feed,Php,Xml,Parsing,Simplexml,Atom Feed,我将这段代码放在一个.atom文档中,该文档用file\u get\u内容包装: <entry> <link type="text/html" rel="alternate" href="..."/> </entry> 但是shell没有给我任何输出。你试过了吗?因为链接元素看起来是空的 <entry> <link type="text/html" rel="alternate" href="...">Somethin

我将这段代码放在一个.atom文档中,该文档用file\u get\u内容包装:

<entry>
    <link type="text/html" rel="alternate" href="..."/>
</entry>

但是shell没有给我任何输出。

你试过了吗?因为链接元素看起来是空的

<entry>
    <link type="text/html" rel="alternate" href="...">Something</link>
</entry>

加载xml文档时,文档是根元素(在本例中为
)。因此,您需要:

$xml = new SimpleXMLElement($XML_file);
$link = $xml->link;
print $link;

完整的atom文档是什么样子的?它是有效的XML吗?@MichaelBerkowski是的,它完全有效。你可以在编辑中看到整个文件。Shell仍然没有给我任何东西。没有“东西”。语法是:`。您可以在编辑中看到整个代码。我无法理解如何操作PHP手册示例中描述的属性。非常感谢,这比我想象的要简单;)请注意,您还可以按名称访问属性值,就像使用数组一样。例如,
echo$xml->entry->link['href']
$text = '<entry><link type="text/html" rel="alternate" href="..." /></entry>';
$xml = simplexml_load_string($text);
$linkAttributes = $xml->link->attributes();
foreach ($linkAttributes as $key => $value)  {
    echo $key . '::' . $value . PHP_EOL;
}
type::text/html
rel::alternate
href::...
$xml = new SimpleXMLElement($XML_file);
$link = $xml->link;
print $link;