Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tDOM - update node value - nodeValue

Status
Not open for further replies.

yodaa

Programmer
Jun 10, 2004
64
SE
Why can't I update the value of a node in my XML file? I can add new nodes with values to the file with "dom createNodeCmd" command, but changing values in the file doesn't work. I get the "NO_MODIFICATION_ALLOWED_ERR" error on the line " $node nodeValue "10000" ". Does anybody have a clue of what might be wrong?


Thanx in advance..



The structure of it is as follows.


# FILE
Code:
<projects>
  <project>
    <id>10024</id>
    <date>2004-08-11</date>
  </project>
  <project>
    <id>10235</id>
    <date>2004-08-11</date>
  </project>
  <project>
    <id>10021</id>
    <date>2004-08-11</date>
  </project>
  <project>
    <id>10214</id>
    <date>2004-08-11</date>
  </project>
</projecs>

# CODE
Code:
# Open a XML file for read/write
# xmlfile - contents of xml file
# fid - channel id of file
# id = 10214

# Create a tDOM doc from file
set doc [dom parse $xmlfile]
	
# Set root tag
set root [$doc documentElement]

# Update project data
# -------------------
foreach projectNode [$root childNodes] {
    # If project_id matches node
    puts "If project_id matches node"
    if {[string match -nocase $id [[$projectNode selectNodes id] text]]} {
        # <id>
        set node [$projectNode selectNodes id]
        $node nodeValue "10000"
        break
    }    
}

# Write XML to file
puts $fid [$root asXML]
# Close channel to file
close $fid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top