Reputation: 27
I try to convert xml from this:
<test>
<sub ID="126754">
<name>test</name>
</sub>
<sub ID="126769">
<name>test2</name>
</sub>
</test>
to this :
<test>
<sub>
<ID>126754</ID>
<name>test</name>
</sub>
<sub>
<ID>126769</ID>
<name>test2</name>
</sub>
</test>
I can read and loop in my file but I don't find how to convert ID=nnnnnn
to <ID>nnnnnn</ID>
Upvotes: 0
Views: 81
Reputation: 311
Try This
$newContent = @()
$test=gc C:\temp\xmll.xml
ForEach($Regel In $Text) {
if($Regel -match "ID=\d{6}") {
$newContent += " <sub>"
$newContent += " <ID>$($Regel.Substring(8, 10))</ID>"
} else {
$newContent += $Regel
}
}
$newContent
Upvotes: 1