これは入力ファイルです:
<root>
<node id="N1">
<fruit id="small_fruit" action="create">
<orange id="1" action="create">
<attribute>
<color>yellow</color>
</attribute>
</orange>
</fruit>
<fruit id="small_fruit" action="create">
<orange id="1" action="destroy">
<attribute>
<color>green</color>
</attribute>
</orange>
</fruit>
</node>
<node id="N2">
<dog id="small_dog">
<poodle id="1" action="create">
<attribute>
<color>Yellow</color>
</attribute>
</poodle>
<terrier id="2" action="create">
<attribute>
<color>White</color>
</attribute>
</terrier>
<poodle id="1" action="change">
<attribute>
<color>Brown</color>
</attribute>
</poodle>
<terrier id="2" action="destroy">
<attribute>
<color>Blue</color>
</attribute>
</terrier>
</dog>
<dog id="small_dog" action="create">
<poodle id="1" action="destroy">
<attribute>
<color>Black</color>
</attribute>
</poodle>
<terrier id="2" action="change">
<attribute>
<color>White</color>
</attribute>
</terrier>
<terrier id="2" action="change">
<attribute>
<color>Grey</color>
</attribute>
</terrier>
</dog>
<dog id="large_dog">
<poodle id="1" action="create">
<attribute>
<color>Red</color>
</attribute>
</poodle>
</dog>
</node>
</root>
これは期待される出力です:
<root>
<node id="N1">
<fruit id="small_fruit" action="create">
</fruit>
<fruit id="small_fruit" action="create">
<orange id="1" action="destroy">
<attribute>
<color>green</color>
</attribute>
</orange>
</fruit>
</node>
<node id="N2">
<dog id="small_dog">
</dog>
<dog id="small_dog" action="create">
<poodle id="1" action="destroy">
<attribute>
<color>Black</color>
</attribute>
</poodle>
<terrier id="2" action="change">
<attribute>
<color>White</color>
</attribute>
</terrier>
<terrier id="2" action="change">
<attribute>
<color>Grey</color>
</attribute>
</terrier>
</dog>
<dog id="large_dog">
<poodle id="1" action="create">
<attribute>
<color>Red</color>
</attribute>
</poodle>
</dog>
</node>
</root>
ルール:
「destroy」メソッドを持つノードが同じ親 (果物または動物) の最後に表示される場合、以前のノードをすべて削除します。
そうでない場合は、「destroy」メソッドを使用したノードを含むすべてのノードを削除し、残りは変更せずに残します。
単純化するには:
- xxx/破棄 -> 破棄
- xxx/destroy/aaa/bbb -> aaa/bbb
要約すると、同じ ID とノード名(orange-id:1 または terrier-id:2 または poodle-id:1)を持つノードをチェックし、同じ親exの下にある必要があります。(果物または犬)