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

Tony Maro tony at maro.net
Mon Oct 31 18:20:51 CET 2005


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.

If you use Lazarus, my TMPack has a XML Treeview component that loads an 
XML file into a TTreeView for visual display.  It might you help 
visualize what's going on better.  I've attached a tiny screenshot based 
on your example XML data.

http://tony.maro.net/mod.php?mod=downloads&op=showcat&id=2&level=1

>Also if we have
>
><tag>
>  <inner_tag>
>.....
>  <inner_tag>
>.....
></tag>
>
>will NodeValue return the string between the <tag> tag ????
>
>  
>
No, it returns nothing, and you'll have to look for child nodes to the 
<tag> to find <inner_tag>. 

The main problem is that you are thinking of an XML file as a text file, 
when in fact it's a string of interconnected objects.  It's kind of like 
thinking of a ".frm" file textually (Is that a word) because it's stored 
as a text file, when in fact it's a represenation of objects that make 
up a form.

-Tony
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xmlview.jpg
Type: image/jpeg
Size: 9123 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20051031/a8418b8c/attachment.jpg>


More information about the fpc-devel mailing list