f



Adding and updating new tDOM XML text nodes

Hi guys,

Some code:

 package require tdom
 # Read in data in the xml variable.
 set dom [dom parse -keepEmpties \
  "<BASE>\n<al>\n<Cats>9 lives</Cats>\n<Canaries/>\n</al>\n</BASE>"]
 set doc [$dom documentElement]
 # Add a missing node.
 set node [$doc selectNodes /BASE/al] 
 $node appendXML "<Dogs></Dogs>"
 # Update an existing node.
 set node [$doc selectNodes /BASE/al/Cats/text()]
 $node nodeValue "Great swingers"
 # Output doc to show Dogs got added and Cats changed.
 puts [$doc asXML]                                               
 # Try to update the node with some data.
 set node [$doc selectNodes /BASE/al/Dogs/text()]
 $node nodeValue "Go Woof"

Output:

 <BASE>
 <al>
 <Cats>Great swingers</Cats>
 
 <Canaries/>
 
 <Dogs/>
     </al>
 
 </BASE>
 
 invalid command name ""
     while executing
 "$node nodeValue "Go Woof""
     (file "t" line 15)

Platform: 

ActiveTCL 8.4.13.0.261555.

Strangeness:

I can add the new node to the XML (and it's even reformatted) for it to
be called in when doing the $doc asXML, but, I can't update a newly
added node.

Anyone have any suggestions?

0
hfrarg3 (215)
9/22/2006 7:58:17 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

1 Replies
813 Views

Similar Articles

[PageSpeed] 42

In article <slrneh8g2p.irn.flavp+hfrarg@sparrow.autons.net.au>,
Synic  <flavp+hfrarg@nhgbaf.arg.nh> wrote:
>Some code:
>
> package require tdom
> # Read in data in the xml variable.
> set dom [dom parse -keepEmpties \
>  "<BASE>\n<al>\n<Cats>9 lives</Cats>\n<Canaries/>\n</al>\n</BASE>"]
> set doc [$dom documentElement]
> # Add a missing node.
> set node [$doc selectNodes /BASE/al] 
> $node appendXML "<Dogs></Dogs>"
                       ^^^^
You add a 'Dogs' node without any childs or content.

> # Update an existing node.
> set node [$doc selectNodes /BASE/al/Cats/text()]
> $node nodeValue "Great swingers"
> # Output doc to show Dogs got added and Cats changed.
> puts [$doc asXML]                                               
> # Try to update the node with some data.
> set node [$doc selectNodes /BASE/al/Dogs/text()]

That is your mistake. With your XPath expression, you select all text
node childs of your newly inserted Dogs element. There aren't any.
Therefor, you get an empty list as result. That is confirmend by your
output, see below


> $node nodeValue "Go Woof" Output:
> <BASE>
> <al>
> <Cats>Great swingers</Cats>
> 
> <Canaries/>
> 
> <Dogs/>

You see: empty 'Dogs' element, no element node childs, no text
content.

>     </al>
> 
> </BASE>
> 
> invalid command name ""
>     while executing
> "$node nodeValue "Go Woof""
>     (file "t" line 15)
>
>Platform: 
>
>ActiveTCL 8.4.13.0.261555.
>
>Strangeness:
>
>I can add the new node to the XML (and it's even reformatted) for it to
>be called in when doing the $doc asXML, but, I can't update a newly
>added node.

You've an at least partly wrong mental model of DOM. From the DOM data
model view, elements and pcdata text are just nodes (of different
types) in the DOM tree. You don't update a newly added node, you
either modify the node value of an already existing text node child of
your element node (if there is already one (btw. there could be more
than one)). Or, as in your case, if your newly added node doesn't have
a text node child, you've to add one. One way to do this in your
example code would be:

set newTextNode [$doc createTextNode "Go Woof"]
set dogsNode [$doc selectNodes /BASE/al/Dogs]
$dogsNode appendChild $newTextNode
    
hth
rolf
0
pointsman (41)
9/24/2006 12:25:11 PM
Reply:

Similar Artilces:

XML DOM: XML/XHTML inside a text node
In my program, I get input from the user and insert it into an XHTML document. Sometimes, this input will contain XHTML, but since I'm inserting it as a text node, xml.dom.minidom escapes the angle brackets ('<' becomes '&lt;', '>' becomes '&gt;'). I want to be able to override this behavior cleanly. I know I could pipe the input through a SAX parser and create nodes to insert into the tree, but that seems kind of messy. Is there a better way? Thanks. On Thu, 2 Nov 2005 noahlt@gmail.com wrote: > In my program, I get input from the us...

The difference between new node() and new node?
now, I define the struct following: struct node { bool match; node* child[27]; }; What's the difference between 1) node *Trie=new node(); and 2) node *Trie = new node; On Sep 5, 6:52=A0pm, remlostime <remlost...@gmail.com> wrote: > now, I define the struct following: > struct node > { > =A0 =A0 =A0 =A0 bool match; > =A0 =A0 =A0 =A0 node* child[27]; > > }; > > What's the difference between > 1) node *Trie=3Dnew node(); and 2) node *Trie =3D new node; no difference. On Sep 5, 12:52 pm, remlostime <remlost...@gmail.com> wrote: > now, I de...

new exams added in Testking.co.uk with new updates
new exams added in Testking.co.uk with new updates and passing guarantee ...

new exams added in Testking.co.uk with new updates
new exams added in Testking.co.uk with new updates and passing guarantee ...

Adding a node in xml
Hi, I got a xml fil: <Ordbog ModuleId="4"> <WordSet Id="cec36468-a624-46af-a51e-e583f52efab6" /> <Ord>return</Ord> <Beskrivelse> test1 </Beskrivelse> <WordSet Id="009f4be5-0481-4a04-a8d2-f817c7e6d48e" /> <Ord>tow</Ord> <Beskrivelse> Fem </Beskrivelse> <WordSet Id="c7b6ae0e-1f74-43d3-839b-24a39f259cb6" /> </Ordbog> I like to adding a node with xslt, so the result looks like that. <Ordbog ModuleId="4"> <Ord> <WordSet Id=&q...

Update XML Node?
Hi Everyone... Needless to say, I'm new to awk. I just found that awk can be used to solve my problem. I have a xml file. I want to update the text of a xml node. For example, <IpAddress>IP_ADDRESS</IpAddress> should be changed to <IpAddress>127.0.0.1</IpAddress> Any idea on how to get this? Thanks in advance, Regards, Kaja On Wednesday 22 October 2008 14:23, Kaja wrote: > Hi Everyone... > > Needless to say, I'm new to awk. I just found that awk can be used to > solve my problem. > > I have a xml file. I want to update the text of ...

XML text node
Hi!In my application, I want to use XML files as configuration files.I made a VI using XML DOM Parser fonctions to fill the text nodes with the desired information. In the case I want to overwrite previous information stored in a node , the data has to be written as text and is placed between the corresponding markers (for exemple in the attached file &lt;InputValue&gt;data&lt;\InputValue&gt;).However if a node is empty (no text previoulsy written), the marker becomes &lt;InputValue/&gt;. In that case, it is impossible to write data in it... Why is that ?I think my code...

ANN: New XML Differencing, Updated XML Mapping in Stylus Studio 5.3
A new update for the Stylus Studio XML IDE adds a new XML Differencing Tool, updated visual XML mapping tools and many other features. Download a free trial of Stylus Studio 5.3 at: http://www.stylusstudio.com/xml_download.html Highlights of new XML Differencing Tool: * Differencing of XML files and folders using a customizable color-coded XML tree view * Support for one-to-one and many-to-one XML file * Step through XML differences node-by-node * View differences using "split-screen" and "merged changes" views * Expand all changes, or collapse identical XML blocks to si...

[ANN] New XML Differencing, Updated XML Mapping in Stylus Studio 5.3
A new update for the Stylus Studio XML IDE adds a new XML Differencing Tool, updated visual XML mapping tools and many other features. Download a free trial of Stylus Studio 5.3 at: http://www.stylusstudio.com/xml_download.html Highlights of new XML Differencing Tool: * Differencing of XML files and folders using a customizable color-coded XML tree view * Support for one-to-one and many-to-one XML file * Step through XML differences node-by-node * View differences using "split-screen" and "merged changes" views * Expand all changes, or collapse identical XML blocks to sim...

ANN: New XML Differencing, Updated XML Mapping in Stylus Studio 5.3
A new update for the Stylus Studio XML IDE adds a new XML Differencing Tool, updated visual XML mapping tools and many other features. Download a free trial of Stylus Studio 5.3 at: http://www.stylusstudio.com/xml_download.html Highlights of new XML Differencing Tool: * Differencing of XML files and folders using a customizable color-coded XML tree view * Support for one-to-one and many-to-one XML file * Step through XML differences node-by-node * View differences using "split-screen" and "merged changes" views * Expand all changes, or collapse identical XML blocks to sim...

ANN: New XML Differencing, Updated XML Mapping in Stylus Studio 5.3 #2
A new update for the Stylus Studio XML IDE adds a new XML Differencing Tool, updated visual XML mapping tools and many other features. Download a free trial of Stylus Studio 5.3 at: http://www.stylusstudio.com/xml_download.html Highlights of new XML Differencing Tool: * Differencing of XML files and folders using a customizable color-coded XML tree view * Support for one-to-one and many-to-one XML file * Step through XML differences node-by-node * View differences using "split-screen" and "merged changes" views * Expand all changes, or collapse identical XML blocks to sim...

Updating A Text String In A Text Field With An Update Query
If I have the following string in a text field of a table: "This is a test" can I create an update query that will change, say, the string "is" to "xyz" in the two locations where it occurs or would this require VBA? Thanks, Sheldon Potolsky Use an Update query. Something like this: UPDATE Table1 SET [F1] = Replace([F1], "is", "xyz") WHERE [F1] Like "*is*"; -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps ...

new security update prevents searching for new updates
I downloaded the new security update and my PB froze while optimizing the disk. I waited 1/2 hour and then shut it off and restarted. Now I cannot use the utility to check for updates! It checks and then tells me that the last update was successful. I've yet to update a number of other things (such as iSync) and would like to know how to get this fixed! Have there been any reported problems with the security update? Thanks In article <11409ukqtepue8b@corp.supernews.com>, Karen <lalla@worstweb.not> wrote: > I downloaded the new security update and my PB froze whil...

how to Update/insert an xml element's text----> (<element> text</element>)
hello friends, how can we update or insert into an xml Element. For example : ------------------- <?xml version="1.0"> <request> <main> <name>ISO8856</name> </main> </request> here when we run a java class file it should replace "ISO8856"with "ISO9001". Any Assistance or example. thanQ in adv. Ajay HANM wrote: > <?xml version="1.0"> > <request> > <main> > <name>ISO8856</name> > </main>...

Web resources about - Adding and updating new tDOM XML text nodes - comp.lang.tcl

Wikipedia:Updating information - Wikipedia, the free encyclopedia
This page documents an English Wikipedia editing guideline . It is a generally accepted standard that editors should attempt to follow, though ...

Facebook Updating Software Development Kit For Apple IOS 6 To Reflect Integration
With Facebook integration officially coming to Apple’s iOS 6 mobile operating system for its iPhone and iPad tablet, what new features are in ...

Updating how Cost per Click is Measured on Facebook
To help advertisers better understand how their ads perform, we're updating the definition of cost per click on Facebook. Learn what the change ...

Updating Your App for iOS 9: What You Need to Know
Updating Your App for iOS 9: What You Need to Know

Facebook for iPhone 3.0 to Include Page Updating
... who want to more easily update their Facebook Pages on the go: Facebook for iPhone 3.0 , which should be released soon, will include Page updating, ...

Updating trends on mobile
Trends are a great way to find out what people are talking about on Twitter at a given moment and at a single glance. Starting today, we’re making ...

Delhi Metro Fare Calculator and Auto-Updating Map on the App Store on iTunes
Get Delhi Metro Fare Calculator and Auto-Updating Map on the App Store. See screenshots and ratings, and read customer reviews.

BlackBerry Bold 9000 Updating #2 - Flickr - Photo Sharing!
Explore berrytokyo's photos on Flickr. berrytokyo has uploaded 126 photos to Flickr.

LOOT v0.7.0 for Mod Organizer: Updating and Installation - YouTube
A new version of LOOT (Load Order Optimisation Tool) has been released with some major upgrades. This video tutorial shows how to upgrade and ...

Updating Emma: Jane Austen's classic joins list of literary reworks
Jane Austen published six novels. Just six. She died before she completed the seventh.

Resources last updated: 2/6/2016 3:12:44 AM