我试图从twitter atom/xml feed获取正确的数据.我在txmldocument中有twitter数据,并试图从中获取一些特定信息.
以下是数据的截断示例:
<entry>
<link type="text/html" rel="alternate" href="http://twitter.com/blub/statuses/1501068" />
<title>title of twitter post goes here</title>
<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/234870532/normal.jpg" />
</entry>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我试图获取配置文件图像url(第二个链接标记的href属性).
如果我使用这样的代码:
i:=xmldocument1.DocumentElement.ChildNodes['entry'];
text:=(i.ChildNodes['link'].GetAttributeNS('href',''));
Run Code Online (Sandbox Code Playgroud)
我得到的是FIRST链接标签的href值,但我想要SECOND链接标签,我不知道该怎么做.有人有什么想法吗?
谢谢.
你可以这样做:
i := xmldocument1.DocumentElement.ChildNodes['entry'];
text := (i.ChildNodes[2].GetAttributeNS('href','')); // notice the [2] index
Run Code Online (Sandbox Code Playgroud)
因为ChildNodes是一个IXMLNodeList对象.确保检查节点"2"是否存在以及是否具有该type="image/png"属性 - 始终验证您的数据.
这是Delphi文档的一部分,
property Nodes[const IndexOrName: OleVariant]: IXMLNode; default;
Run Code Online (Sandbox Code Playgroud)
描述
读取节点以访问列表中的指定节点.
IndexOrName标识所需的节点.有可能
- 节点的索引,其中0是第一个节点的索引,1是第二个节点的索引,依此类推.Count属性提供您可以指定的索引的上限.
- 列表中节点的LocalName属性.
如果IndexOrName未标识列表中的节点,并且包含此节点列表的父文档的文档在其Options属性中包含doNodeAutoCreate,则节点列表将尝试创建具有IndexOrName指定的名称的新节点.如果节点列表无法创建新节点,则会引发异常.