我有许多具有不同节点结构和不同节点的xml文件。现在我想将这两个 xml 文件合并到一个 xml 文件中。经过搜索,我发现我可以使用xslt来合并多个xml文件,并且每个示例都处理具有相同节点结构的xml文件。
感谢斯蒂芬的建议,但我面临着不同的情况。以下是我想要合并在一起的 xml 文件片段,最终的 xml 文件应该如下所示。
文件1.xml
<Equipment>
<Items>
<Item>
<ID>_stdpart_38100</ID>
<Index>1</Index>
<SubcategoryIDRef>Power</SubcategoryIDRef>
</Item>
</Items>
<Subcategories>
<Subcategory>
<ID>Power</ID>
<CategoryIDRef>Power and Handling</CategoryIDRef>
</Subcategory>
<Categories>
<Category>
<ID>Power and Handling</ID>
<Title>Power and Handling</Title>
<Subtitle />
</Category>
<Categories>
</Equipment>
文件2.xml
<Models>
<Model>
<ID>S Sedan</ID>
<Name>S Sedan</Name>
<Index>1</Index>
<Equipment>
<Item>
<IDRef>_stdpart_38100</IDRef>
<Optionality>S</Optionality>
</Item>
<Equipment>
</Model>
</Models>
最终的合并文件应该如下所示 合并.xml
<Models>
<Model>
<ID>S Sedan</ID>
<Name>S Sedan</Name>
<Index>1</Index>
<Equipment>
<Item>
<ID>_stdpart_38100</ID>
<Index>1</Index>
<Subcategory>
<ID>Power</ID>
<Category>
<ID>Power and Handling</ID>
<Title>Power and Handling</Title>
<Subtitle />
</Category>
</Subcategory>
<Optionality>S</Optionality>
</Item>
</Equipment>
</Model>
</Models>
最佳答案
I found that i can use xslt for merging multiple xml files and every example is dealing with xml files having same nodal structure.
下面是一个示例,其中 XML 文件具有完全不同的结构:
如果这没有帮助,请使用 XML 示例以及您需要的合并文件的外观来更新您的问题。
关于java - 如何在java或任何其他工具中将具有不同节点结构的多个xml文件合并到单个xml文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11155497/