Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

XML Iteration

19 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lee Jenkins

This isn't still true for latter version of FPC like 2.4.1, right?

http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes

"A quick note on navigating the DOM tree: When you need to access nodes in sequence, it is best to use FirstChild and NextSibling properties (to iterate forward), or LastChild and PreviousSibling (to iterate backward). For random access it is possible to use ChildNodes or GetElementsByTagName methods, but these will create a TDOMNodeList object which eventually must be freed. This differs from other DOM implementations like MSXML, because FCL implementation is object-based, not interface-based. "

I think I read that had been "fixed".

Thanks,

Warm Regards, Lee

Reply by email

Frank Church
to Lee Jenkins

I am glad to see someone with an interest in FPCs XML. Do you have some experience with XPath usage in PFC/Lazarus?

Lee Jenkins wrote 26 lines
This isn't still true for latter version of FPC like 2.4.1, right? http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes "A quick note on navigating the DOM tree: When you need to access nodes in sequence, it is best to use FirstChild and NextSibling properties (to iterate forward), or LastChild and PreviousSibling  (to iterate backward). For random access it is possible to use ChildNodes  or GetElementsByTagName methods, but these will create a TDOMNodeList object which eventually must be freed. This differs from other DOM implementations like MSXML, because FCL implementation is object-based, not interface-based. " I think I read that had been "fixed". Thanks, -- Warm Regards, Lee _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Lee Jenkins
to Frank Church
Frank Church wrote
I am glad to see someone with an interest in FPCs XML. Do you have some experience with XPath usage in PFC/Lazarus?

No, other than some cursory google searches. I figured I'd be asking about that myself soon.

Warm Regards, Lee

Reply by email

Frank Church
to Luiz Americo Pereira Camara

Thanks for the link. What is WST? My searches turn up something related to eclipse.

Luiz Americo Pereira Camara wrote 16 lines
Frank Church escreveu: > > I am glad to see someone with an interest in FPCs XML. Do you have > some experience with XPath usage in PFC/Lazarus? > > In this program: http://www.silvioprog.com.br/downloads/Cliente_SOAP_SAH.zip?attredirects=0&d=1 you can find a simple usage of XPath + WST Luiz _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Marco van de Voort
to Lee Jenkins: This isn't still true for latter version of FPC like 2.4.1, right?…

In our previous episode, Lee Jenkins said:

Show quoted text 13 lines
This isn't still true for latter version of FPC like 2.4.1, right? http://wiki.freepascal.org/XML_Tutorial#Printing_the_names_of_nodes "A quick note on navigating the DOM tree: When you need to access nodes in sequence, it is best to use FirstChild and NextSibling properties (to iterate forward), or LastChild and PreviousSibling (to iterate backward). For random access it is possible to use ChildNodes or GetElementsByTagName methods, but these will create a TDOMNodeList object which eventually must be freed. This differs from other DOM implementations like MSXML, because FCL implementation is object-based, not interface-based. " I think I read that had been "fixed".

Most, if not all trunk XML fixes have been merged to 2.4.1. And there were a lot of them, thanks to Sergei.

Reply by email

Frank Church
to Luiz Americo Pereira Camara: Web Services Toolkit: http://wiki.lazarus.freepascal.org/Web_Service_Toolkit Luiz

The funny thing is I have already read that wiki page, but did not recognize it in your description.
When I added 'pascal' to the Google search, then it turned up on the first page..

FreePascal users ought to blog some more. ;-)

Luiz Americo Pereira Camara wrote 14 lines
Frank Church escreveu: > > Thanks for the link. What is WST? My searches turn up something > related to eclipse. > > Web Services Toolkit: http://wiki.lazarus.freepascal.org/Web_Service_Toolkit Luiz _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Lee Jenkins
to Luiz Americo Pereira Camara: In this program: http://www.silvioprog.com.br/downloads/Cliente_SOAP_SAH.zip?attredirects=…
Luiz Americo Pereira Camara wrote 6 lines
Frank Church escreveu: > I am glad to see someone with an interest in FPCs XML. Do you have > some experience with XPath usage in PFC/Lazarus? > >

Luiz,

In Unit1.pas:

XPathResult := EvaluateXPathExpression('//Descricao', XmlTree.DocumentElement);
   if (XPathResult  nil) then
   begin
     for i := 0 to XPathResult.AsNodeSet.Count - 1 do
     begin
       Node := TDOMNode(XPathResult.AsNodeSet[i]);
       if Node.FirstChild  nil then
         Memo1.Lines.Add(UTF8Encode(Node.FirstChild.NodeValue));
     end;
     XPathResult.Destroy;
   end;
   XmlTree.Free;

Why the call to XPathResult.Destroy ? Is it for reference counting? Just seems something else to remember (use destroy instead of free)...

Thanks

Warm Regards, Lee

Reply by email

Luiz Americo Pereira Camara
to Lee Jenkins
Lee Jenkins wrote 29 lines
Luiz Americo Pereira Camara wrote: > Frank Church escreveu: >> I am glad to see someone with an interest in FPCs XML. Do you have >> some experience with XPath usage in PFC/Lazarus? >> >> > Luiz, In Unit1.pas: XPathResult := EvaluateXPathExpression('//Descricao', XmlTree.DocumentElement); if (XPathResult nil) then begin for i := 0 to XPathResult.AsNodeSet.Count - 1 do begin Node := TDOMNode(XPathResult.AsNodeSet[i]); if Node.FirstChild nil then Memo1.Lines.Add(UTF8Encode(Node.FirstChild.NodeValue)); end; XPathResult.Destroy; end; XmlTree.Free; Why the call to XPathResult.Destroy ? Is it for reference counting? Just seems something else to remember (use destroy instead of free)...

No special reason.

Free is redundant in this case since i already knows that XPathResult nil

Luiz

Show quoted text 12 lines
Thanks -- Warm Regards, Lee _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Frank Church
to Luiz Americo Pereira Camara

I am having some problems with XPath.

EvaluateXPathExpression raises exceptions with some search strings and I am not sure if it is my limited knowledge of XPath, or a buggy XPath implementation.

The attached demo uses the example from
http://www.w3schools.com/xpath/xpath_examples.asp and I am running 0.9.28.2 beta on Windows

Luiz Americo Pereira Camara wrote 61 lines
Lee Jenkins escreveu: Luiz Americo Pereira Camara wrote: > >> Frank Church escreveu: >> >>> I am glad to see someone with an interest in FPCs XML. Do you have >>> some experience with XPath usage in PFC/Lazarus? >>> >>> >>> >> >> > Luiz, > > In Unit1.pas: > > XPathResult := EvaluateXPathExpression('//Descricao', > XmlTree.DocumentElement); > if (XPathResult nil) then > begin > for i := 0 to XPathResult.AsNodeSet.Count - 1 do > begin > Node := TDOMNode(XPathResult.AsNodeSet[i]); > if Node.FirstChild nil then > Memo1.Lines.Add(UTF8Encode(Node.FirstChild.NodeValue)); > end; > XPathResult.Destroy; > end; > XmlTree.Free; > > > Why the call to XPathResult.Destroy ? Is it for reference counting? Just > seems something else to remember (use destroy instead of free)... > No special reason. Free is redundant in this case since i already knows that XPathResult nil Luiz > Thanks > > -- > Warm Regards, > > Lee > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Lee Jenkins
to Frank Church
Frank Church wrote 11 lines
I am having some problems with XPath. EvaluateXPathExpression raises exceptions with some search strings and I am not sure if it is my limited knowledge of XPath, or a buggy XPath implementation. The attached demo uses the example from http://www.w3schools.com/xpath/xpath_examples.asp and I am running 0.9.28.2 beta on Windows

I'm trying to put together a simple test application for xpath now and I've noticed, there doesn't seem to be a way in fpc xml implementation to simply save to a string, an xml document or node.

ReadXML()
ReadXMLFile()

All have no implementation to write a value to a string, only Text, Stream and File. I have to create an intermediary stream, save it to that and then convert that to string or use TStringStream in order to convert them to a string. Odd.

Also the wiki page:
http://wiki.freepascal.org/XML_Tutorial#Create_a_TXMLDocument_from_a_string

Is incorrect. The example will error out because the string passed in is interpreted as a file path, not as a string representation of an xml document.

Warm Regards, Lee

Reply by email

Lee Jenkins
to Frank Church: I am having some problems with XPath. EvaluateXPathExpression raises exceptions with some…
Frank Church wrote 6 lines
I am having some problems with XPath. EvaluateXPathExpression raises exceptions with some search strings and I am not sure if it is my limited knowledge of XPath, or a buggy XPath implementation.

The XPath implementation works flawlessly with the examples given on w3schools.com site's xpath tutorial.

See the attached simple lcl project. Compile it and then copy and paste examples from the w3schools site and you'll see fpc xpath implementation will make you smile.

Warm Regards, Lee

Reply by email

Frank Church
to Lee Jenkins

I have run it with some success.

What I find missing now is the ability to give the correct output for a an index value, such as //bookstore/book[1]/title. It works on the w3schools version but not in the FPC one.

Are we on the same versions of Lazarus and XPath?

Lee Jenkins wrote 25 lines
Frank Church wrote: > I am having some problems with XPath. > > EvaluateXPathExpression raises exceptions with some search strings and I > am not sure if it is my limited knowledge of XPath, or a buggy XPath > implementation. > > The XPath implementation works flawlessly with the examples given on w3schools.com site's xpath tutorial. See the attached simple lcl project. Compile it and then copy and paste examples from the w3schools site and you'll see fpc xpath implementation will make you smile. -- Warm Regards, Lee _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Lee Jenkins
to Frank Church
Frank Church wrote 6 lines
I have run it with some success. What I find missing now is the ability to give the correct output for a an index value, such as //bookstore/book[1]/title. It works on the w3schools version but not in the FPC one.

Try changing to only using one front slash instead of two:

/bookstore/book[price>35.00]/title

^--- One slash

If I'm not mistaken, // means from current node, search. / means the entire document. Not sure what you're intent is with the example so that may be exactly what you're trying to do.

Warm Regards, Lee

Reply by email

Frank Church
to Lee Jenkins

When I try it the /bookstore/book[price>35.00]/title I get the error

Conversion from node set to number not possible. The error is the same whether I use a // or a / .

Are we using the same version? Marco's notes refer to updates made in FPC 2.4.1 and I am using 2.2.4 with Lazarus 0.9.28

Lee Jenkins wrote 28 lines
Frank Church wrote: > I have run it with some success. > > What I find missing now is the ability to give the correct output for a an > index value, such as //bookstore/book[1]/title. It works on the w3schools > version but not in the FPC one. > > Try changing to only using one front slash instead of two: /bookstore/book[price>35.00]/title ^--- One slash If I'm not mistaken, // means from current node, search. / means the entire document. Not sure what you're intent is with the example so that may be exactly what you're trying to do. -- Warm Regards, Lee _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Frank Church ======================= http://devblog.brahmancreations.com

Reply by email

Lee Jenkins
to Frank Church
Frank Church wrote 9 lines
When I try it the /bookstore/book[price>35.00]/title I get the error Conversion from node set to number not possible. The error is the same whether I use a // or a / . Are we using the same version? Marco's notes refer to updates made in FPC 2.4.1 and I am using 2.2.4 with Lazarus 0.9.28

0.9.29 rev 23574 with FPC 2.4.1

Warm Regards, Lee

Reply by email

Luiz Americo Pereira Camara
to Lee Jenkins: I'm trying to put together a simple test application for xpath now and I've noticed,…
Lee Jenkins wrote 29 lines
Frank Church wrote: > I am having some problems with XPath. > > EvaluateXPathExpression raises exceptions with some search strings > and I am not sure if it is my limited knowledge of XPath, or a buggy > XPath implementation. > > The attached demo uses the example from > http://www.w3schools.com/xpath/xpath_examples.asp and I am running > 0.9.28.2 beta on Windows > > I'm trying to put together a simple test application for xpath now and I've noticed, there doesn't seem to be a way in fpc xml implementation to simply save to a string, an xml document or node. ReadXML() ReadXMLFile() All have no implementation to write a value to a string, only Text, Stream and File. I have to create an intermediary stream, save it to that and then convert that to string or use TStringStream in order to convert them to a string. Odd. Also the wiki page: http://wiki.freepascal.org/XML_Tutorial#Create_a_TXMLDocument_from_a_string

May be this can help you:

procedure Str2XmlFile(var XmlTree: TXMLDocument; const S: String);
var
  Stream: TStringStream;
begin
  Stream := TStringStream.Create(S);
  try
    ReadXmlFile(XmlTree, Stream);
  finally
    Stream.Destroy;
  end;
end;

Luiz

Show quoted text 14 lines
Is incorrect. The example will error out because the string passed in is interpreted as a file path, not as a string representation of an xml document. -- Warm Regards, Lee _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email