回复 12# 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("//rehearsal[contains(text(), 'ABC')]")
- $b.ParentNode.RemoveChild($b)
-
- $a.save("b.xml")
复制代码
|