5i365 (我心飞扬)当前离线
上尉
TOP
idwma 当前离线
少校
$test = @' <?xml version="1.0" encoding="UTF-8"?> <score-partwise version="3.1"> <part id="P1"> <measure number="1" width="118.81"> <direction placement="above"> <direction-type> <rehearsal default-x="-20.55" relative-y="30.00" font-weight="bold" font-size="14">ABC</rehearsal> </direction-type> </direction> <direction placement="above"> <direction-type> <rehearsal default-x="-40.55" relative-y="60.00" font-weight="bold" font-size="14">CDE</rehearsal> </direction-type> </direction> </measure> </part> </score-partwise> '@ [xml]$a = $test $b = $a.SelectSingleNode("//*[./.='ABC']") $b.ParentNode.RemoveChild($b) $a.save("b.xml")复制代码
$test = @' <?xml version="1.0" encoding="UTF-8"?> <score-partwise version="3.1"> <part id="P1"> <measure number="1" width="118.81"> <direction placement="above"> <direction-type> <rehearsal default-x="-20.55" relative-y="30.00" font-weight="bold" font-size="14">ABC</rehearsal> </direction-type> </direction> <direction placement="above"> <direction-type> <rehearsal default-x="-40.55" relative-y="60.00" font-weight="bold" font-size="14">CDE</rehearsal> </direction-type> </direction> </measure> </part> </score-partwise> '@ [xml]$a = $test $b = $a.SelectSingleNode("//rehearsal[contains(text(), 'ABC')]") $b.ParentNode.RemoveChild($b) $a.save("b.xml")复制代码
$a="\s*<.*>[\r\n\s]*<.*>[\r\n\s]*<.*>ABC<.*>[\r\n\s]*<.*>[\r\n\s]*<.*>" sc b.xml ([io.file]::ReadAllText("a.xml") -replace "$a",'') -encoding utf8复制代码
https://docs.microsoft.com/zh-cn/previous-versions/dotnet/netframework-4.0/ms256086(v=vs.100)复制代码
[xml]$a=type a.xml $b=$a.SelectSingleNode("//descendant::direction[direction-type/rehearsal='ABC']") $b.ParentNode.RemoveChild($b) $a.save("b.xml")复制代码
sc b.xml ([io.file]::ReadAllText("a.xml") -replace '\s*<direction.*>[\r\n\s]*<.*>ABC<[\s\S]*?/direction>','')复制代码