here is my structure of xml document,
<worldpatentdata>
<patent-family>
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
<familymember>.....</familymember>
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
<familymember>.....</familymember>
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
<familymember>.....</familymember>
</patent-family>
</worldpatentdata>
In the above xml structure,all the <exchange-documents>
element is found to be child node of <patent-family>
element.
I want these <exchange-documents>
elements as childnode of <family-member>
element,so that the xml have the following structure,
<worldpatentdata>
<patent-family>
<familymember>.....
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
</familymember>
<familymember>.....
<exchange-开发者_运维知识库documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
</familymember>
<familymember>.....
<exchange-documents>......</exchange-documents>
<exchange-documents>......</exchange-documents>
</familymember>
</patent-family>
</worldpatentdata>
can anybody help me on this? thanks
Iterate over the children of <patent-family>
via the DOM, remembering every <exchange-documents>
you encounter along the way. Whenever you see a <familymember>
, move the remembered elements under it.
Above the top of my head, one way could be to:
- Use
XDocument
to load the xml, and create a tempXDocument. foreach (XElement...
through the elements and add to XmlNodeList items which are<exchange-documents>
- Add
<familymember>
in tempXDocument when<familymember>
is found; and add the XmlNodeList to tempXDocument. - Save the tempXDocument.
精彩评论