vendredi 6 mars 2015

Delphi find xml node


Vote count:

0




I'm trying do solve a very simple thing here: I want to find a node by name and read its text.



Function GetNodeText(xml,targetNode,value:string):String;
var
xmldoc : IXMLDocument;
root: IXMLNode;
i: LongInt;
x:integer;
s: string;
begin
xmlDoc := newXMLDocument;
xmlDoc.LoadFromXML(xml);
xmlDoc.Active := true;

root := XMLDoc.DocumentElement;

for i := 0 to xmlDoc.ChildNodes[root.NodeName].ChildNodes.Count -1 do
begin
s := xmlDoc.DocumentElement.ChildNodes[i].NodeName;
x := CompareStr(s, targetNode);
if x = 0 then //targetnode Node found
begin
try
result := xmlDoc.DocumentElement.ChildNodes[i].ChildNodes.FindNode(value).Text;
Except
result := '';
end;
exit;
end
end
end;


My function works only for the childs of the rootNode. How can I browse through ALL of the existing nodes of an XML document until I reach the end ?



asked 19 secs ago







Delphi find xml node

Aucun commentaire:

Enregistrer un commentaire