Each node in the XML will be represented as an IXMLNode
in the IXMLDocument
, in the same hierarchy that they appear in the XML. It would help if you first look at the XML with the nodes indented so you can see the hierarchy more clearly:
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">
<statusInfo>
<vendorClaimID>BRADY12478018AETNA</vendorClaimID>
<statusID>0</statusID>
<statusDescription>Unvalidated</statusDescription>
</statusInfo>
</string>
One you understand the hierarchy, you can write code for it:
var
doc: IXMLDocument;
statusInfo: IXMLNode;
vendorClaimID: String;
statusID: Integer;
statusDescription: String;
begin
doc := LoadXMLData(xmlString);
statusInfo := doc.DocumentElement.ChildNodes['statusInfo'];
vendorClaimID := statusInfo.ChildNodes['vendorClaimID'].Text;
statusID := StrToInt(statusInfo.ChildNodes['statusID'].Text);
statusDescription := statusInfo.ChildNodes['statusDescription'].Text;
end;
Alternatively:
var
doc: IXMLDocument;
statusInfo: IXMLNode;
vendorClaimID: String;
statusID: Integer;
statusDescription: String;
begin
doc := LoadXMLData(xmlString);
statusInfo := doc.DocumentElement.ChildNodes['statusInfo'];
vendorClaimID := VarToStr(statusInfo.ChildValues['vendorClaimID']);
statusID := StrToInt(VarToStr(statusInfo.ChildValues['statusID']));
statusDescription := VarToStr(statusInfo.ChildValues['statusDescription']);
end;
If you use Delphi's XML Data Binding wizard, it will generate interfaces that will parse the XML for you:
var
doc: IXMLDocument;
statusInfo: IXMLstatusInfoType;
vendorClaimID: String;
statusID: Integer;
statusDescription: String;
begin
doc := LoadXMLData(xmlString);
statusInfo := Getstring(doc).statusInfo;
vendorClaimID := statusInfo.vendorClaimID;
statusID := statusInfo.statusID;
statusDescription := statusInfo.statusDescription;
end;