- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在加载 XML Feed,它可以工作。但我的 xpath 查询中似乎遗漏了一些东西。其实我想阅读标题节点的注释,但它似乎不起作用。
$xml = simplexml_load_file( $feed_url );
$comment = $xml->xpath('//channel/item[1]/title//comment()');
提要具有以下结构
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>My main feed</title>
<description>feed description</description>
<link>http://www.example.com</link>
<language>en_US</language>
<lastBuildDate>Wed, 26 Nov 2014 11:44:13 UTC</lastBuildDate>
<item>
<title><!-- Special Image --></title>
<link></link>
<guid>http://www.example.com/page/345</guid>
<media:category>horizontal</media:category>
<media:thumbnails>
<media:thumbnail url="www.example.com/test.jpg" type="image/jpeg" height="324" width="545" />
</media:thumbnails>
</item>
<item>
<title>Here's a normal title</title>
<description><![CDATA[Description Text]]></description>
<link></link>
<guid>http://www.example.com/page/123</guid>
<media:category>horizontal</media:category>
</item>
</channel>
</rss>
有人知道我如何阅读评论吗?
最佳答案
或者,您可以使用 DOMDocument
来访问这些注释。示例:
$dom = new DOMDocument();
$dom->load($feed_url);
$xpath = new DOMXpath($dom);
$comment = $xpath->evaluate('string(//channel/item[1]/title/comment())');
echo $comment;
关于PHP SimpleXML 使用 xPath 读取注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27147700/
这里发生了什么事? $string = XML; $xml = simplexml_load_string($string); // $xmlobj = sim
当我将 SimpleXML 解析为对象数组的一部分的字符串时,我一直坚持让 SimpleXML 返回一个对象。 $a = '1145869290false43false'; $resultA = si
我有两个 SimpleXML 对象。如何将一个对象添加为另一个对象的子元素。 请注意,这不能通过 addChild 方法完成,因为它会在添加之前将给定值转换为字符串。 最佳答案 我发现 SimpleX
http://pastie.org/1701923这是从我查询邮政编码的 API 返回的 XML。 我想从每个条目中提取数据,然后直接对其进行循环或将其放入我可以循环的数组中。我似乎无法正确处理。这是
这个问题在这里已经有了答案: remove xml version tag when a xml is created in php (10 个答案) 关闭 7 年前。 我使用 SimpleXML
与 DOM 或 Expat 解析器相比,SimpleXML 仅仅用几行代码就可以从 XML 元素中读取文本数据。 SimpleXML 可把 XML 文档(或 XML 字符串)转换为对象,比如:
我有一些看起来像这样的 XML: true 42 ;jsessionid=42 SimpleXML 以这种方式解析它: $obj
我有一个具有命名空间属性的 XML 文档。 XML 看起来像: 我如何提取 and
我想从元素id的属性创建一个数组,但是以下代码返回所有XML。 PHP文件: $xmlfile=simplexml_load_file("test.xml"); $test=$xmlfile->xpa
我有一个看起来像这样的XML结构: 0 Some survey question Answer 1 0 Answ
我正在尝试访问具有命名空间声明的节点中没有命名空间声明的节点列表。我的 XML 文件有一个带有命名空间 ehd 的主节点,在同一命名空间内有两个子节点 header、body。但是,主体节点内的所有子
我正在使用 SimpleXML 和 XPath 尝试获取子节点('IndexEntry)属性('indexKey')的值。节点的命名空间,我已在另一个节点(“记录”)上成功测试。由于某种原因,该节点的
我有两棵 XML 树,想将一棵树作为叶子添加到另一棵树上。 显然: $tree2->addChild('leaf', $tree1); 不起作用,因为它仅复制第一个根节点。 好吧,所以我想我应该遍历整
我正在使用 SimpleXML http://simple.sourceforge.net/home.php 在我的 Android 应用程序中, 我从 API 获取数据如下:
我想使用 SimpleXML 读取并解析包含员工信息的 XML 文件。框架。这是我的 XML 文件: 29 Pankaj
我正在尝试在 android 中使用 simplexml 解析此 xml 字符串: " " 是的,我知道门标签应该立即关闭,而不是在声明所有门标签后关闭,我无法控制这个
我有一个具有这种结构的 XML 文件:
请,我需要解析包含汽车信息的 XML 文件。我在汽车、照片中完成了所有操作,但我需要在额外的表中包含 id、汽车表 id 的外键,并且所有汽车都有随机的 Equipment_id。 我需要将其放入“设
我有一个看起来像这样的 xml: 在 xml 映射 java 代码中我有这样的东西: public class A { @Element(required=false)
我有一个xml文档如下: Calculations Description First Description Alan
我是一名优秀的程序员,十分优秀!