I want to split an XML document into several XML documents with the specified node name (similar to string.Split (...).)
Example. I have the following xml document.
<root> <nodeA> Hello </nodeA> <nodeA> <nodeB> node b Text </nodeB> <nodeImage> image.jpg </nodeImage> </nodeA> <nodeA> node a text </nodeA> </root>
I want to split this XML document into 3 parts into 'nodeImage' and keep the original xml structure. (Note: a node named "nodeImage" can be anywhere)
1.xml to nodeImage
2.xml for nodeImage
3.xml after nodeImage
For an xml sample, the results should be:
XML document 1:
<root> <nodeA> Hello </nodeA> <nodeA> <nodeB> node b Text </nodeB> </nodeA> </root>
XML Document 2:
<root> <nodeA> <nodeImage> image.jpg </nodeImage> </nodeA> </root>
XML Document 3:
<root> <nodeA> node a text </nodeA> </root>
Does anyone know if there is a good algorithm or existing code sample for this requirement?
Update Notes:
If there is only one node in the xml document named "nodeImage", this XML document should always be divided into three xml documents.
source share