これは、別の現実的な解決策です。
program NodeAccess;
{$APPTYPE CONSOLE}
(*
Assumption
<item>
<name>Manggo Salad</name>
<feature>Good</feature>
<feature>Excelent</feature>
<feature>Nice Food</feature>
<feature>love this</feature>
</item>
as XML is stored in "sample.xml" file along with binary executable
of this program.
Purpose
How to iterate multiple occurence of the "feature" node
*)
uses
SysUtils,
NativeXML;
const
cXMLFileName = 'sample.xml';
var
i,j: Integer;
AXMLDoc: TNativeXml;
begin
try
Writeln('Sample iterating <',cXMLFileName,'>');
Writeln;
AXMLDoc := TNativeXml.Create(nil);
try
AXMLDoc.LoadFromFile(cXMLFileName);
if Assigned(AXMLDoc.Root) then
with AXMLDoc.Root do
for i := 0 to NodeCount - 1 do
begin
if Nodes[i].Name='feature' then
for j := 0 to Nodes[i].NodeCount - 1 do
Writeln(' ',Nodes[i].Name, ' >>> ', Nodes[i].Nodes[j].Value)
end;
finally
AXMLDoc.Free;
end;
Writeln;
Writeln('Hit Return to quit');
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.