Adriaan Boshoff
asked on
Reading XML data if there is no top level element in delphi
I'm trying to read an xml response from a api but I keep getting the following error:
How can I read the xml data if the response looks like this:
My current code:
How can I read the xml data if the response looks like this:
<status>success</status><statusmsg>online</statusmsg><vmstat>online</vmstat><hostname>quantum.vps</hostname><ipaddress>xxx.xx.xx.xxx</ipaddress>
My current code:
procedure TfrmMain.btn1Click(Sender: TObject);
var
httpclient: TIdHTTP;
doc: TXMLDocument;
data: IXMLNode;
begin
httpclient := TIdHTTP.Create(nil);
try
doc := TXMLDocument.Create(nil);
try
doc.XML.Text := httpclient.Get('https://site.com/api.php?action=status'); //Modified URL for experts exchange
doc.Active := True;
data := doc.DocumentElement;
lbl1.Text := data.ChildNodes['status'].Text;
finally
doc.Free;
end;
finally
httpclient.Free;
end;
end;
ASKER
@aikimark Now it just gives me a invalid pointer operation.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, you changed statement 11 and got an invalid pointer operation?
i'd use PosEx instead
it allows you to search from a specific position
and thus allows to return multiple items within same tags
it allows you to search from a specific position
and thus allows to return multiple items within same tags
You would have a better solution if you used the regular expression object to do your parsing. You could populate and return a TDictionary (hash table) of the tags and their values from a single function call.
ASKER
I found this to be easier and faster.
Open in new window