3

Looking for readable example use of Omni Xml package.

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

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.

ain
  • 22,394
  • 3
  • 54
  • 74
none
  • 4,669
  • 14
  • 62
  • 102
  • This question is similar to [this one](http://stackoverflow.com/questions/5513917/delphi-xe-omnixml-using-selectnode). It shows how to access child nodes. Does it help? – Ken White Aug 24 '11 at 17:06

1 Answers1

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.

none
  • 4,669
  • 14
  • 62
  • 102
gabr
  • 26,580
  • 9
  • 75
  • 141
  • XMLEnumNodes, is overloaded with 3 functions, for enumaration by node by xml or by nodelist. very useful for "for". – none Aug 25 '11 at 09:07