简体   繁体   English

如何将子节点设置为XML的父节点?

[英]How to set child nodes into parent nodes in XML?

I have an XML document in this format: 我有以下格式的XML文档:

<EX>
    <file filename="File1">
        <form name="form1"/>
        <form name="form2"/>
        <form name="form3"/>
    </file>
    <file filename="File2">
        <form name="form2"/>
        <form name="form3"/>
    </file>
</EX>

... which I need to convert to this format: ...我需要将其转换为以下格式:

<EX>
    <form name = "form1">
        <file filename="File1"/>
    </form>
    <form name = "form2">
        <file filename="File1"/>
        <file filename="File2"/>
    </form>
    <form name = "form3">
        <file filename="File1"/>
        <file filename="File2"/>
    </form>
</EX>

Can anybody help me with this? 有人可以帮我吗?

Heres one way you could do it: 这是您可以做到的一种方法:

loop through your original xml doc and create a new one with a node for each child node in your original doc. 遍历原始xml文档,并为原始文档中的每个子节点创建一个新的节点。 Then loop through your original document again, creating corresponding children in your new doc. 然后再次遍历原始文档,在新文档中创建相应的子代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM