xml - 使用 SAXParser 合并两个 xml 文件,方法是避免重复节点并在节点重复时添加新属性在 Java 代码中
问题描述
我需要帮助在 java 中合并两个 xml 文件,如果 file2.xml 中有任何新的 mbean 标记,我应该添加,如果应该忽略 100% 重复节点,那么如果现有节点具有 axtra 属性,我需要合并只有属性而不是完整的节点。
file1.xml
<system name="" ostype="DummyOs" version="1">
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass1">
<attribute id="Manufacturer" type="text" value="" />
</mbean>
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass2>
<attribute id="Manufacturer" type="text" value="" />
</mbean>
</system>
file2.xml
<system name="" ostype="dummyOs" version="1">
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass1">
<attribute id="Manufacturer" type="text" value="" />
<attribute id="New_Manufacturer" type="text" value="" /></mbean>
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass2>
<attribute id="Manufacturer" type="text" value="" />
</mbean>
</system>
output.xml
<system name="" ostype="DummyOs" version="1">
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass1">
<attribute id="Manufacturer" type="text" value="" />
<attribute id="New_Manufacturer" type="text" value="" />
</mbean>
<mbean component="CIM" type="" mbclass="" cimclass="DummyClass2>
<attribute id="Manufacturer" type="text" value="" />
</mbean>
</system>
解决方案
推荐阅读
- javascript - Javascript dataTransfer.setData 在 Internet Explorer 中将文本添加到剪贴板
- html - 屏幕宽度为 90% 的响应式 HTML 表格
- c++ - "的多重定义
" 使用 cpp 编译 cuda 代码时出错 - c - DMA 代理以及它如何用于将以太网帧复制到用户缓冲区
- java - 在使用类加载器或资源工具时,在 Jboss 中读取文件会导致异常
- react-native - 反应原生元素无法识别样式化组件自定义字体
- python - 如何以二进制格式存储来自 NEST 模拟器的记录数据?
- reactjs - 在 React Native 中同时运行任务
- nginx - Nginx 身份验证在根页面(HTTPS)上不起作用
- gstreamer - 在 ubuntu1804 上编译 Gstreamer/orc 0.4.32 以使用 ninja 在 rootfs 中运行 arm 发生未定义的引用异常