[英]How to convert property in XML with powershell?
我嘗試從中轉換xml:
<test>
<sub ID="126754">
<name>test</name>
</sub>
<sub ID="126769">
<name>test2</name>
</sub>
</test>
對此:
<test>
<sub>
<ID>126754</ID>
<name>test</name>
</sub>
<sub>
<ID>126769</ID>
<name>test2</name>
</sub>
</test>
我可以讀取並循環進入文件,但是找不到如何將ID=nnnnnn
轉換為<ID>nnnnnn</ID>
嘗試這個
$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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.