gpt4 book ai didi

xml - Delphi - XML - 子节点 - 获取属性

转载 作者:数据小太阳 更新时间:2023-10-29 02:49:33 24 4
gpt4 key购买 nike

我正在尝试从 Twitter atom/xml 提要中获取正确的数据。我在 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>

我遇到的问题是我正在尝试获取个人资料图片 url(第二个链接标记的 href 属性)。

如果我使用这样的代码:

i:=xmldocument1.DocumentElement.ChildNodes['entry'];
text:=(i.ChildNodes['link'].GetAttributeNS('href',''));

我得到的是 FIRST 链接标签的 href 值,但我想要 SECOND 链接标签,但我不知道该怎么做。有人有什么想法吗?

谢谢。

最佳答案

你可以这样做:

i := xmldocument1.DocumentElement.ChildNodes['entry'];
text := (i.ChildNodes[2].GetAttributeNS('href','')); // notice the [2] index

因为 ChildNodes 是一个 IXMLNodeList 对象。确保检查节点“2”是否存在以及它是否具有 type="image/png" 属性 - 始终验证您的数据。

这是 Delphi 文档的一部分,

property Nodes[const IndexOrName: OleVariant]: IXMLNode; default;

Description

Read Nodes to access a specified node in the list.

IndexOrName identifies the desired node. It can be

  • The index of the node, where 0 is the index of the first node, 1 is the index of the second node, and so on. The Count property provides an upper bound on the indexes you can specify.
  • The LocalName property of a node in the list.

If IndexOrName does not identify a node in the list, and if the document that contains this node list’s parent includes doNodeAutoCreate in its Options property, then the node list tries to create a new node with the name specified by IndexOrName. If the node list can’t create the new node, it raises an exception.

关于xml - Delphi - XML - 子节点 - 获取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1084160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com