Re: XML - Find and replace text
- From: Georgios Petasis <petasis@xxxxxxxxxxxxxxxxx>
- Date: Wed, 19 Sep 2007 19:52:09 +0300
O/H gcgaim@xxxxxxxxx έγραψε:
On Sep 19, 10:52 am, schl...@xxxxxxxxxxxxxxxx wrote:gcg...@xxxxxxxxx wrote:On Sep 19, 10:48 am, gcg...@xxxxxxxxx wrote:Cleanest is probably using XSLT with the tdom package.What would be the cleanest way to parse an XML file and replaceI'm using ActiveTcl if that makes any difference.
certain pieces of text that match a specified pattern? I'm going to
know the exact "location" as in the text is always going to be at:
<a>
<b>
<c=stuff>text to replace here</c></b></a>
Any help is appreciated!
Michael
OK, so assuming the XML structure is:
<install>
<service>
...
</service>
<service>
<url>
<data name="config1>this is what I want to change</data>
</url>
</service>
</install>
How do I set the value in <data name=config1>. This is what I have so
far.
package require tdom
set fp [open "config.xml" r]
set xml [read $fp]
set doc [dom parse $xml]
set root [$doc documentElement]
Thank you again!
Lets add some xpath search to the game :-)
set nodes [$root selectNodes {/install/service/url/data[@name="config1"]}]
(or equivalently set nodes [$root selectNodes {//data[@name="config1"]}])
foreach node $nodes {
$node setAttribute name new-value
}
puts [$doc asXML]
George
.
- Follow-Ups:
- Re: XML - Find and replace text
- From: gcgaim
- Re: XML - Find and replace text
- References:
- XML - Find and replace text
- From: gcgaim
- Re: XML - Find and replace text
- From: gcgaim
- Re: XML - Find and replace text
- From: schlenk
- Re: XML - Find and replace text
- From: gcgaim
- XML - Find and replace text
- Prev by Date: Re: Scilab and Tcl/Tk
- Next by Date: Can the name of an alias be retrieved when used to call a command
- Previous by thread: Re: XML - Find and replace text
- Next by thread: Re: XML - Find and replace text
- Index(es):
Relevant Pages
|