c# - Algorithm for xml document splitting -
i want split xml document several xml documents specified node name, (similar string.split(...).)
example: have following xml document.
<root> <nodea> hello </nodea> <nodea> <nodeb> node b text </nodeb> <nodeimage> image.jpg </nodeimage> </nodea> <nodea> node text </nodea> </root>
i want split xml document 3 parts 'nodeimage', , keep original xml structure. (note: node name 'nodeimage' anywhere)
1. xml before nodeimage
2. xml nodeimage
3. xml after nodeimage
for sample xml, 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 text </nodea> </root>
does know if there algorithm, or existing code sample requirement?
update notes:
if there 1 node name 'nodeimage' in xml document, xml document should splitted 3 xml documents.
xelement xe = xelement.load(xmlfile); foreach(xelement newxe in xe.elements("nodea")) { xelement root = new xelement("root",newxe); root.save(newfile); }
Comments
Post a Comment