This is my xml file:
<File>
<Paths>
<Path>
<Node>
<NodeName>Initial_Node</NodeName>
<InnerNode>
<Signal>Test_sig</Signal>
<InnerNode>
<Signal>Test_sig_1</Signal>
<NodeRef>Ref0</NodeRef>
</InnerNode>
</InnerNode>
</Node>
</Path>
<Path>
<Node>
<NodeName>Name1</NodeName>
<InnerNode>
<Signal>Test_sig_0</Signal>
<InnerNode>
<Signal>Test_sig_2</Signal>
<NodeRef>Ref1</NodeRef>
</InnerNode>
</InnerNode>
</Node>
</Path>
</Paths>
<Paths>
<Path>
<Node>
<NodeRef>Ref0</NodeRef>
<InnerNode>
<Signal>Test_sig_3</Signal>
<InnerNode>
<Signal>Test_sig_4</Signal>
<NodeName>Final_Node</NodeName>
</InnerNode>
</InnerNode>
</Node>
</Path>
</Paths>
</File>
I am using lxml in Python.
I want to be able to attach the matching <NodeRef>
in the above file, and then merge the rest of the two matching paths together to get the following result:
<File>
<Paths>
<Path>
<Node>
<NodeName>Initial_Node</NodeName>
<InnerNode>
<Signal>Test_sig</Signal>
<InnerNode>
<Signal>Test_sig_1</Signal>
<InnerNode>
<Signal>Test_sig_3</Signal>
<InnerNode>
<Signal>Test_sig_4</Signal>
<NodeName>Final_Node</NodeName>
</InnerNode>
</InnerNode>
</InnerNode>
</InnerNode>
</Node>
</Path>
<Path>
<Node>
<NodeName>Name1</NodeName>
<InnerNode>
<Signal>Test_sig_0</Signal>
<InnerNode>
<Signal>Test_sig_2</Signal>
<NodeRef>Ref1</NodeRef>
</InnerNode>
</InnerNode>
</Node>
</Path>
</Paths>
</File>
Many thanks for your help
So there wasn't too much detail to go on here, but this at least give the correct output: