I want to split up an XML file according to a certain node's different attributes creating separated XML files all with the same nodes in the top part of the file followed by the node + attribute and its underlying contents until the end of this node.
All separated XML files than need to end with similar end nodes.
Example XML file:
<?xml version=""1.0"" encoding=""UTF-8""?>
<node1>
<node2>
<node3 attribute='1'>item</node3>
<node3 attribute='2'>item</node3>
<node3 attribute='3'>item</node3>
</node2>
<node6 attribute='1'>
<node7>item = (node3 attribute2)</node7>
<node8>item = (node3 attribute3)</node8>
</node6>
<node6 attribute='2'>
<node9>item = (node3 attribute1)</node9>
<node10>item = (node3 attribute2)</node10>
</node6>
</node1>
From this example I want to use the attribute of node6 to be the breakpoint of creating a new XML file. Resulting in 2 XML files looking like this:
Separated XML 1:
<?xml version=""1.0"" encoding=""UTF-8""?>
<node1>
<node2>
<node3 attribute='1'>item</node3>
<node3 attribute='2'>item</node3>
<node3 attribute='3'>item</node3>
</node2>
<node6 attribute='1'>
<node7>item = (node3 attribute2)</node7>
<node8>item = (node3 attribute3)</node8>
</node6>
Separated XML 2:
<?xml version=""1.0"" encoding=""UTF-8""?>
<node1>
<node2>
<node3 attribute='1'>item</node3>
<node3 attribute='2'>item</node3>
<node3 attribute='3'>item</node3>
</node2>
<node6 attribute='2'>
<node9>item = (node3 attribute1)</node9>
<node10>item = (node3 attribute2)</node10>
</node6>
</node1>
I have been looking and working with all these answers but they did not help me to find the right code to do as mentioned above.
https://stackoverflow.com/questions/30374533/split-xml-files-newbie
How to split an xml file in vb
Splitting Xml Document according to node
Can someone help me figure out what the best way to do this is?