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.
Thanks for the great feedback everyone. I noticed that the wiki does in
fact show the "Delphi way" of accessing a node's text which kind of
threw me off. I propose to add the following to the wiki under
"Networking" under the Basic Example section:
For Delphi Programmers:
Note that when working with TXMLDocument, the text within a Node is
considered a separate TEXT Node. As a result, you must access a node's
text value as a separate node. For instance, consider the following XML:
<code>
<?xml version="1.0" encoding="utf-8"?>
<request>
<request_type>PUT_FILE</request_type>
<username>123</username>
<password>abc</password>
</request>
</code>
Consider also the following code example:
<code>
var
PassNode: TDOMNode;
Doc: TXMLDocument;
begin
Doc := TXMLDocument.Create;
// Read in xml file from disk
ReadXMLFile(Doc, 'c:\xmlfiles\test.xml');
// Retrieve the "password" node
PassNode := Doc.DocumentElement.FindNode('password');
// Write out value of the selected node
WriteLn(PassNode.NodeValue); // will be blank
// The text of the node is actually a separate child node
WriteLn(PassNode.FirstChild.NodeValue); // correctly prints "abc"
</code>
I figured this might save new Laz/FPC users a bit of consternation.
Any suggestions or objections to me adding the above to the
wiki/networking/Basic Example section?
(http://wiki.lazarus.freepascal.org/Networking#Basic_Example)
--
Warm Regards,
Lee
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives