Sign in Join

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

Mailing lists / fpc-devel / 2005-10

How to get contents of TDOMNode.NodeValue ???

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Alexander Todorov

Hi all,
I have a XML document and need just a part from it. A simple message to show on a dialog.
<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 ?

Also if we have

<tag>
<inner_tag>
.....
<inner_tag>
.....
</tag>

will NodeValue return the string between the <tag> tag ????

I've noticed that thare is no simple way to get / set that string as it is in delphi / msxml.

Regards.

Reply by email

Tony Maro
to Alexander Todorov
Alexander Todorov wrote 13 lines
<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

Show quoted text 13 lines
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

Reply by email

Michael Van Canneyt
to Tony Maro
Tony Maro wrote 22 lines
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.FirstChildNil then
  MsgText:=MsgNode.FirstChild.NodeValue;

Should do more or less what you expect.

Michael.

Reply by email