Lazarus
Programming => Networking and Web Programming => Topic started by: BlueIcaro on July 09, 2021, 09:14:39 am
-
Hello I tryng to read a xhtml+file response from a webserve.
Here is a example of the response:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Services</title>
<base href="http://localhost:80/" /> </head>
<body>
<div class="state"> <a href="" rel="self" />
<ul>
<li class="srvlst-service-li" title="ctrl"> <a href="ctrl" rel="self"> </a> </li>
<li class="srvlst-service-li" title="rw"> <a href="rw" rel="self"> </a> </li>
<li class="srvlst-service-li" title="progress"> <a href="progress" rel="self"> </a> </li>
<li class="srvlst-service-li" title="fileservice"> <a href="fileservice" rel="self"> </a> </li>
<li class="srvlst-service-li" title="users"> <a href="users" rel="self"> </a> </li>
<li class="srvlst-service-li" title="subscription"> <a href="subscription" rel="self"> </a> </li>
</ul>
</div>
</body>
</html>
But When I try to read with ReadXMLFile procedure I got a excepcion: "Root element missing".
I use this code:
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
-
Hi, I found that if I read the xml response from a file, I don't have any error. :(
/BlueIcaro
-
Try setting stream position to 0.
-
Hello, Finally I found the solution:
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