Recent

Author Topic: TXMLNode  (Read 13755 times)

wluis

  • New Member
  • *
  • Posts: 16
TXMLNode
« on: April 27, 2010, 06:58:59 pm »
Somebody knows how i can find class: TXMLNode on lazarus/freepascal

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: TXMLNode
« Reply #1 on: April 27, 2010, 07:15:35 pm »
Why would you need it?
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

dfeher

  • New Member
  • *
  • Posts: 19
Re: TXMLNode
« Reply #2 on: April 27, 2010, 07:33:39 pm »
I think you should use TDOMNode instead.  ::)

wluis

  • New Member
  • *
  • Posts: 16
Re: TXMLNode
« Reply #3 on: April 28, 2010, 05:04:33 pm »
ok i´m working in a project with MapServer, and i need read xml document, their came from url request, now,  ReadXMLFile don´t work what i must to do

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: TXMLNode
« Reply #4 on: April 28, 2010, 06:42:46 pm »
Code: [Select]
uses
  DOM, XMLRead;
...

var root: TDOMNode;
    xml: TXMLDocument;
  ...
  ReadXMLFile(xml, '<yourfile>');
  root := xml.FindNode('<your root tag>');
  // etc...

This should work (it does for me...).

All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TXMLNode
« Reply #5 on: April 28, 2010, 11:16:53 pm »
@eny:
Then the OP must save the url request response first. I seldom use fcl-xml, so I can't give any solution. TJSONParser has two constructors, one accepting file and the other accepting string. Isn't there any XML counterpart for this?

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: TXMLNode
« Reply #6 on: April 29, 2010, 03:05:19 pm »
@Leledumbo
You con load it from a TStringStram:

Code: [Select]
procedure MyClass.LoadXMLFromString(const AValue: string);
var
   AStream: TStringStream;
begin
   AStream := nil;
   if Assigned(FXML) then begin
      FreeAndNil(FXML);
      FXML := TXMLDocument.Create;
   end;
   AStream := TStringStream.Create(AValue);
   try
      if Assigned(AStream) then begin
         ReadXMLFile(FXML, AStream);
      end;
   finally
      FreeAndNil(AStream);
   end;
end;

wluis

  • New Member
  • *
  • Posts: 16
Re: TXMLNode
« Reply #7 on: April 29, 2010, 04:36:03 pm »
OK, they work, now: i need to know if exist an a class on free pascal similar to HttpWebRequest and WebRequest of C#.
If exist any place (url) when i could find it please post me.....
thanks...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TXMLNode
« Reply #8 on: April 30, 2010, 07:07:29 am »
I don't use C# (though I can read it), so I don't know what those two classes do. Please post what you want to achieve. From my guess, it looks like you want to do some http networking. You can use LNet for that.

wluis

  • New Member
  • *
  • Posts: 16
Re: TXMLNode
« Reply #9 on: May 03, 2010, 01:22:15 pm »
LeleDumbo you got the reason, but, i have use Indy 10 , you know how i can work with that??

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: TXMLNode
« Reply #10 on: May 03, 2010, 03:00:15 pm »
I can recommend using Synapse. Doing webrequests with it is dead simple. The httpsend unit contains a method HttpGetBinary which can be used with a TMemoryStream. Then you can simply load the document from that

vfclists

  • Hero Member
  • *****
  • Posts: 1165
    • HowTos Considered Harmful?
Re: TXMLNode
« Reply #11 on: May 03, 2010, 09:51:59 pm »

This is some sample code what process XML in an http request with Indy. I have omitted a lot of object allocation code for brevity sake, but you should be able to work it out.

xdrEventServer is TIdHttpServer component and xdrEventServerCommandGet is its request processing event, OnCommandGet.

  ARequestInfo.PostStream.Position := 4

This is used because the XML at 5 characters into the data.

The code receives a request, parses out the XML body and prints out the XML keys which are loaded in InitKeyStrings. You will probably need some of these units in your program.

IdCustomTCPServer, IdContext, IdTCPClient, IdComponent,
  IdHTTPServer, IdAntiFreeze, IdCustomHTTPServer, IdURI, DOM, xmlread

If you are going to use XPath get a more recent version as there are bugs in the older implementations. Check the attachment and
http://lists.freepascal.org/lists/fpc-pascal/2010-May/024929.html


Code: [Select]
procedure TdmSocketExplorer.xdrEventServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  postStrings, valStrings, keyStrings: TStringList;
  XML: TXMLDocument;
  strStream, xdrStream: TStringStream;
  xdrString: ansistring;
 
  procedure InitKeyStrings;
  begin
    keyStrings.AddStrings(uIF.mmoXDRKeys.Lines);
  end;

  procedure AddToDisplayMemo;
  var
    i: integer;
  begin
    uIF := utilitiesInterfaceForm;
    uIF.mmoXDRXML.Lines.Clear;
    uIF.mmoXDRXMLHistory.Lines.Add('== xdrString - Start ==');

    for i := 0 to keyStrings.Count - 1 do
    begin
      uIF.mmoXDRXML.Lines.Add(keyStrings.Strings[i] + ' => ' + valStrings.Strings[i]);
      uIF.mmoXDRXMLHistory.Lines.Add(keyStrings.Strings[i] + ' => ' + valStrings.Strings[i]);
    end;
    uIF.mmoXDRXML.Lines.Add('==xdr XML end==');
    uIF.mmoXDRXMLHistory.Lines.Add('== xdrString - End ==');

    uIF.mmoXML.Lines.Add('== xdr XML start ==');
    uIF.mmoXML.Lines.AddStrings(postStrings);
    uIF.mmoXML.Lines.Add('== xdr XML end ==');

  end;


begin

  InitializeObjects;

  ARequestInfo.PostStream.Position := 4;
  postStrings.LoadFromStream(ARequestInfo.PostStream);
  postStrings.Text := TIdUri.URLDecode(postStrings.Text);
  xdrStream := TStringStream.Create(postStrings.Text);

  GetXMLValues(xdrStream, keyStrings, valStrings);
  AddToDisplayMemo;
 
  DestroyObjects;

end;


procedure GetXMLValues(xdrStream: TStringStream; keyStrings: TStringList; valStrings: TStringList);
var
  XML: TXMLDocument;
  i, j: integer;
  nodeList: TDomNodeList;
begin
  ReadXMLFile(XML, xdrStream);
  for j := 0 to keyStrings.Count - 1 do
  begin
    nodeList := XML.GetElementsByTagName(keyStrings.Strings[j]);
    if nodeList.Count > 0 then
    begin
      for i := 0 to 0 do //I need only the first matching item
      begin
        valStrings.Add(TIdURI.Urldecode(nodeList[i].TextContent));
      end
    end else
    begin
      valStrings.Add('<null>');
    end;
    nodeList.Free;
  end;
  XML.Free;
end;

LeleDumbo you got the reason, but, i have use Indy 10 , you know how i can work with that??
Lazarus 3.0/FPC 3.2.2

wluis

  • New Member
  • *
  • Posts: 16
Re: TXMLNode
« Reply #12 on: May 04, 2010, 02:20:22 pm »
ok, i undersand yours point of view, but, i don´t need work with Indy 9 or 10 y must work with that,
i´m ending my thesis for my college, for me, the  work with indy is madatory

 

TinyPortal © 2005-2018