Recent

Author Topic: [Solved] Reading xhtml+xml response: root missing  (Read 4027 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 791
    • Blog personal
[Solved] Reading xhtml+xml response: root missing
« 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:
Quote
<?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:
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
« Last Edit: July 22, 2021, 12:48:55 pm by BlueIcaro »

BlueIcaro

  • Hero Member
  • *****
  • Posts: 791
    • Blog personal
Re: Reading xhtml+xml response: root missing
« Reply #1 on: July 09, 2021, 10:31:53 am »
Hi, I found that if I read the xml response from a file, I don't have any error.  :(

/BlueIcaro

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Reading xhtml+xml response: root missing
« Reply #2 on: July 09, 2021, 11:02:20 am »
Try setting stream position to 0.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

BlueIcaro

  • Hero Member
  • *****
  • Posts: 791
    • Blog personal
[Solved] Reading xhtml+xml response: root missing
« Reply #3 on: July 22, 2021, 12:37:02 pm »
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

 

TinyPortal © 2005-2018