On Sun, 3 Dec 2006, Lee wrote:

> 
> Hi,
> 
> I am trying to get up to speed with the TXMLDocument object and it seems
> pretty straight forward.  However, I am having a problem retrieving the text
> value of a node.
> 
> Given the following simple xml:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <settings>
>    <login>
>       <username>123</username>
>       <password>123</password>
>    </login>
> </settings>
> 
> The following code fails to print the values (NodeValue) to the console:
> 
> var
> Doc: TXMLDocument;
> Node1, Node2: TDOMNode;
> i: Integer
> Begin
> Doc := TXMLDocument.create;
> 
> if (FileExists('sys_info.xml')) then
>    XMLREAD.ReadXMLFile(Doc, 'sys_info.xml');
> Node1 := Doc.DocumentElement.FindNode('login');
> 
> for i := 0 to Node1.ChildNodes.Count -1 do
>    begin
>    writeln(node1.ChildNodes.Item[i].NodeName + ' ' +
>       node1.ChildNodes.Item[i]).NodeValue);
>    end;
> 
> end;
> 
> The above code correctly prints out the .NodeName, but not the .NodeValue.
> 
> Referencing the wiki/networkiing/basic example:
> http://wiki.lazarus.freepascal.org/Networking#Basic_Example
> 
> It looks like .NodeValue is what I'm looking for.  Just am not sure why the
> values are not being retrieved.

Because they are in a TEXT subnode of the nodes you are printing.

You should be doing:

 for i := 0 to Node1.ChildNodes.Count -1 do
   begin
   SN:=Node1.ChildNodes.Item[i];
   write(SN.NodeName + ' ');
   If SN.ChildNodes.Count>0 then
     Writeln(SN.ChildNodes[0].NodeValue)
   else
     Writeln('<empty>');
   end;


Michael.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to