[Solved] Reading xhtml+xml response: root missing
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
BlueIcaro · 2021-07-09 07:14
Hello I tryng to read a xhtml+file response from a webserve.
Here is a example of the response:
Quote
Services
But When I try to read with ReadXMLFile procedure I got a excepcion:
"Root element missing".
I use this code:
Code: [Select]var
F: TMemoryStream;
DOC: TXMLDocument;
begin
F := TMemoryStream.Create;
F.WriteAnsiString(mmEntrada.Lines.Text);
ReadXMLFile(doc,F);
doc.Free;
F.Free;
end;
May be I using a wrong method?. How can I read and work with this
response from web?
I attach a example program
Thanks
/BlueIcaro
----------------------------------------------------------------------
BlueIcaro · 2021-07-09 08:31
Hi, I found that if I read the xml response from a file, I don't have
any error.
/BlueIcaro
----------------------------------------------------------------------
Mr.Madguy · 2021-07-09 09:02
Try setting stream position to 0.
----------------------------------------------------------------------
BlueIcaro · 2021-07-22 10:37
Hello, Finally I found the solution:
Code: [Select]
var
Cadena: string;
s: TStringStream;
XmlDoc: TXMLDocument;
hijo: TDOMNodeList;
begin
Cadena := mmEntrada.Lines.Text;
s := TStringStream.Create(Cadena);
ReadXMLFile(XmlDoc, s);
hijo := XmlDoc.GetChildNodes;
if hijo <> nil then
mmResultado.Lines.Add('Tiene hijos');
end;
/BlueIcaro