omn​​i xml,是否有一个简单的当前示例来读取xml文件?

时间:2022-12-23 22:48:44

Looking for readable example use of Omni Xml package.

寻找Omni Xml包的可读示例使用。

the documentation now is 2 examples, for loading and writing, nothing about reading, nor iterating.

现在的文档是两个例子,用于加载和编写,没有关于阅读,也没有迭代。

could you provide a simple reading Xml ,example of one repeatable property

你能提供一个简单的阅读Xml,一个可重复属性的例子

such as

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

how to iterate over all the values and get the p1 property.

如何迭代所有值并获取p1属性。

1 个解决方案

#1


6  

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;

Warning: Untested, written in browser.

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

#1


6  

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;

Warning: Untested, written in browser.

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