【问题标题】:omni xml , is there a simple current example for reading xml file?omn​​i xml,是否有一个简单的当前示例来读取 xml 文件?
【发布时间】:2011-08-24 15:08:35
【问题描述】:

寻找 Omni Xml 包的可读示例。

文档现在是 2 个示例,用于加载和写入,与读取无关,也没有迭代。

您能否提供一个简单的阅读 XML,一个可重复属性的示例

<root>
<value p1=1></value>
<value p1=2 p2='32432'/>
<value p1=3 p3='fdsf'><other></other></value>
</root>

如何遍历所有值并获取 p1 属性。

【问题讨论】:

  • 这个问题类似于this one。它显示了如何访问子节点。有帮助吗?

标签: xml delphi delphi-2009 omnixml


【解决方案1】:
uses
  OmniXML,
  OmniXMLUtils;

var
  node : IXMLNode;
  other: IXMLNode;
  xml  : IXMLDocument;
begin
  xml := CreateXMLDoc;
  if XMLLoadFromFile(xml, 'fname.xml') then begin // 3 more notes
    for node in XMLEnumNodes(xml,'/root/value') do begin
      Writeln(GetNodeAttrStr(node, 'p1', ''), ';', GetNodeAttrStr(node, 'p2', ''), ';', 
        GetNodeAttrStr(node, 'p3', ''));
      other := SelectNode(node, 'other');
    end;
  end;
end;

警告:未经测试,在浏览器中编写。

【讨论】:

  • XMLEnumNodes 重载了 3 个函数,用于通过 xml 或节点列表按节点枚举。对于“for”非常有用。
猜你喜欢
  • 2011-08-02
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 2011-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多