0

I need to parse out some values from xml file. The problem is - that I must do it with Delphi =(. the file is quite simple

<?xml version="1.0"?>
<Items version="1.0">
  <Item BackupFileName="d:\data.bak">
    <Rating Rate="TOP"/>
  </Item>
  <Item BackupFileName="d:\data2.bak">
    <Rating Rate="OTHER"/>
  </Item>
  ....
</Items>

And I just need an array of strings with this filepaths {"d:\data.bak", "d:\data2.bak", ... } I have googled a little and found a solution (as I thought) like

 url := 'D:\Backups.xml';
  xml := CreateOleObject('Microsoft.XMLDOM') as IXMLDOMDocument;
  xml.async := False;
  xml.load(url); // or use loadXML to load XML document using a supplied string
  if xml.parseError.errorCode <> 0 then
    raise Exception.Create('XML Load error:' + xml.parseError.reason);

  nodes_row := xml.selectNodes('/Items');
  for i := 0 to nodes_row.length - 1 do
  begin
    node := nodes_row.item[i];
    result := node.selectSingleNode('Item').text;
end;

But result seems to be always void. Could you please provide or refer an easy solution for this?

zohak
  • 21
  • 6

1 Answers1

0

Use the IXMLNode.Attributes property Or the IXMLNode.AttributeNodes property, since your nodes don't contain text, you actually looking for attribute text.

Alec
  • 569
  • 2
  • 17
  • 27