i want to know how to change XML and Save
for example,this is test1.xml
<AAA_KEY>
<Account_key> 123AA03 </Account_key>
<KEY ID = "User10036">
<key1> #1199DERE45 </key1>
<key2> 455DSuyeias </key2>
</AAA_KEY>
and then,i have a web.config
<www>
<KEY ID = "User10036">
<user> user1 </user>
<key1> xxxxxx </key1>
<www>
so,i want to know how to read key1 , copy to web.config and save
for example
<www>
<KEY ID = "User10036">
<user> user1 </user>
<key1> #1199DERE45 </key1>
<www>
Your xmls are not well formed... the KEY
tag needs to be closed. I've edited it to how I think it should be below, change it in your question if that's not right.
# read the files as xml objects
[xml]$test1 = Get-Content C:\temp\test1.xml
[xml]$webconfig = Get-Content C:\temp\web.config
# for testing, I'm just going to create the objects. you don't need to do this.
[xml]$test1 = @"
<AAA_KEY>
<Account_key> 123AA03 </Account_key>
<KEY ID = "User10036">
<key1> #1199DERE45 </key1>
<key2> 455DSuyeias </key2>
</KEY>
</AAA_KEY>
"@
[xml]$webconfig = @"
<www>
<KEY ID = "User10036">
<user> user1 </user>
<key1> xxxxxx </key1>
</KEY>
</www>
"@
# set the value
$webconfig.www.KEY.key1 = $test1.AAA_KEY.KEY.key1
# save web.config
$webconfig.Save("C:\temp\web.config")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.