【发布时间】:2012-04-12 06:48:48
【问题描述】:
我有一个格式如下的 XML:
<Accounts>
<Account ID="1" City="Bangalore" Amount="2827561.95" />
<Account ID="225" City="New York" Amount="12312.00" />
<Account ID="236" City="London" Amount="457656.00" />
<Account ID="225" City="London" Amount="23462.40" />
<Account ID="236" City="Bangalore" Amount="2345345.00" />
</Accounts>
在这里,使帐户独一无二的是属性ID 和City 的组合。
我如何唯一地阅读Amount?如何读取 ID 和 City 属性组合的数量?
例如,我需要为具有ID=225 和City=London 的帐户获取Amount。如果我使用类似的代码
Node.GetAttribute('ID')=225
它总是给我第一个 ID=225 的节点
谢谢你。
【问题讨论】:
-
你如何使用
Node.GetAttribute('ID')=225?你是循环使用还是...? -
是的..我在循环中使用它。类似... Node:=rootNode.ChildNodes.FindNode('Accounts'); for i := 0 to Node.ChildNodes.Count - 1 do begin childnode:= Node.ChildNodes[i]; if Node.HasAttribute('ID') then amount:=Node.GetAttribute('ID'); …..
-
然后你可以在你的 if 语句中添加第二个条件来比较
City的内容。
标签: xml delphi delphi-2010