How can i update the value of number in the xml?

您所在的位置:网站首页 微信里的摇骰子怎么玩 How can i update the value of number in the xml?

How can i update the value of number in the xml?

2023-03-11 15:29| 来源: 网络整理| 查看: 265

I'm assuming that you want to sort the "page" elements into ascending order based on the value of each elements' "number" attribute?

This will do that and save the modified XML file at the end.

$x = @' '@ $xml = [xml]$x $SortedPageElements = $xml.pages.page | sort {[int]$_.number} $xml.pages.page | ForEach-Object{ $_.ParentNode.RemoveChild($_) | Out-Null } $SortedPageElements | ForEach-Object{ $xml.DocumentElement.AppendChild($_) | Out-Null } $xml.Save('c:\junk\new.xml')

Note that the new file will have numeric values for the "number" attributes' value. The XML you posted has text values and if you sort those you won't have the sort turn out the way I think you want it to.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3