[fpc-devel] How to get contents of TDOMNode.NodeValue ???

Michael Van Canneyt michael at freepascal.org
Tue Nov 1 10:28:56 CET 2005



On Mon, 31 Oct 2005, Tony Maro wrote:

> Alexander Todorov wrote:
>
> ><document>
> >....
> > <message>Hello word</message>
> >....
> ></document>
> >
> >I did :
> >
> >ShowMessage(Document.FindNode('message').NodeValue)
> >but it returns an empty string. Showing NodeName returns 'message'.
> >How to get the contents of the <message> tag ???? Is it working ?
> >
> >
> The real problem is that the computer recognized that it is NOT a true
> "Hello World" message (word, not world) and it refused to display due to
> the typo ;-)  just kidding.
>
> As I recall, there's another child node in the object heiarchy when you
> have text between the tags.  It's a "#text" subnode to the "message"
> node.  Someone with more experience in that can expound.

This is correct.
The name of the node is '#text', it's NodeValue property contains the actual text.

MsgNode:=Document.FindNode('message');
If MsgNode.FirstChild<>Nil then
  MsgText:=MsgNode.FirstChild.NodeValue;

Should do more or less what you expect.

Michael.




More information about the fpc-devel mailing list