Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
合并2个XML文件_Xml_Merge - Fatal编程技术网

合并2个XML文件

合并2个XML文件,xml,merge,Xml,Merge,我尝试了很多不同的方法,比如合并2个XML文件,比如XSTL1.0。但我仍然不是100%有能力。它需要在Linux和Windows上工作,现在我不管它是如何工作的,它只需要工作。所以如果它使用一个工具,jar,XSTL1.0,2.0,3.0或者其他什么。只要它工作简单,易于更改,我就可以。它应该尽可能通用 基本上,输入XML包含完整的XML结构。 如果名称匹配(且属性具有相同的值),则应从第二个文件中获取该值。如果第二个XML包含新元素,则应添加它 此外,XML文件中的不同位置上还有NVPair

我尝试了很多不同的方法,比如合并2个XML文件,比如XSTL1.0。但我仍然不是100%有能力。它需要在Linux和Windows上工作,现在我不管它是如何工作的,它只需要工作。所以如果它使用一个工具,jar,XSTL1.0,2.0,3.0或者其他什么。只要它工作简单,易于更改,我就可以。它应该尽可能通用

基本上,输入XML包含完整的XML结构。 如果名称匹配(且属性具有相同的值),则应从第二个文件中获取该值。如果第二个XML包含新元素,则应添加它

此外,XML文件中的不同位置上还有NVPairs(名称-值对)。如果名称匹配,则值字段的值应取自第二个文件。如果第二个文件包含新的名称-值对,则应将其添加到结果中

我想出了一个简单的例子

输入:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://www.test.com/xmlns/Test" name="TEST">
    <repoInstanceName>testRepo</repoInstanceName>
    <NVPairs name="Global Variables">
        <NameValuePair>
            <name>Host</name>
            <value>localhost</value>
        </NameValuePair>
        <NameValuePairInteger>
            <name>Timeout</name>
            <value>60</value>
        </NameValuePairInteger>
    </NVPairs>
    <repoInstances selected="local">
        <localRepoInstance>
            <encoding>UTF-8</encoding>
        </localRepoInstance>
    </repoInstances>
    <services>
        <bw name="1.par">
            <enabled>true</enabled>
            <bindings>
                <binding name="1">
                    <machine>localhost</machine>
                    <product>
                        <type>testtype</type>
                        <version>12.9</version>
                    </product>
                    <contact>mailme</contact>
                    <setting>
                        <enableVerbose>false</enableVerbose>
                        <threadCount>12</threadCount>
                        <java>
                            <initHeapSize>128</initHeapSize>
                            <maxHeapSize>256</maxHeapSize>
                            <threadStackSize>512</threadStackSize>
                        </java>
                    </setting>
                    <shutdown>
                        <checkpoint>true</checkpoint>
                        <timeout>0</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>Trace.Task.*</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>false</value>
                </NameValuePair>
            </NVPairs>
            <failureCount>0</failureCount>
            <failureInterval>0</failureInterval>
            <bwprocesses>
                <bwprocess name="process1">
                    <starter>name</starter>
                    <enabled>true</enabled>
                    <maxJob>8</maxJob>
                    <activation>true</activation>
                    <flowLimit>8</flowLimit>
                </bwprocess>
            </bwprocesses>
            <checkpoints selected="Local File">
                <checkpoint>Local File</checkpoint>
                <checkpoint>/lalaa/</checkpoint>
                <tablePrefix>ffffl_7787</tablePrefix>
            </checkpoints>
            <isFt>false</isFt>
        </bw>
        <bw name="2.par">
            <enabled>true</enabled>
            <bindings>
                <binding name="2">
                    <machine>other</machine>
                    <product>
                        <type>testtype2</type>
                        <version>12.9</version>
                    </product>
                    <contact>mailme</contact>
                    <setting>
                        <enableVerbose>false</enableVerbose>
                        <threadCount>12</threadCount>
                        <java>
                            <initHeapSize>128</initHeapSize>
                            <maxHeapSize>256</maxHeapSize>
                            <threadStackSize>512</threadStackSize>
                        </java>
                    </setting>
                    <shutdown>
                        <checkpoint>true</checkpoint>
                        <timeout>0</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>Trace.Task.*</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>false</value>
                </NameValuePair>
            </NVPairs>
            <failureCount>0</failureCount>
            <failureInterval>0</failureInterval>
            <bwprocesses>
                <bwprocess name="process1">
                    <starter>name</starter>
                    <enabled>true</enabled>
                    <maxJob>8</maxJob>
                    <activation>true</activation>
                    <flowLimit>8</flowLimit>
                </bwprocess>
                <bwprocess name="process2">
                    <starter>name</starter>
                    <enabled>true</enabled>
                    <maxJob>8</maxJob>
                    <activation>true</activation>
                    <flowLimit>8</flowLimit>
                </bwprocess>                
            </bwprocesses>
            <checkpoints selected="Local File">
                <checkpoint>Local File</checkpoint>
                <checkpoint>/lalaa/</checkpoint>
                <tablePrefix>ffffl_7787</tablePrefix>
            </checkpoints>
            <isFt>false</isFt>
        </bw>       
    </services>
</application>

测试报告
主办
本地服务器
超时
60
UTF-8
真的
本地服务器
测试类型
12.9
邮寄
假的
12
128
256
512
真的
0
Trace.Task*
假的
EnableMemorySavingMode
假的
0
0
名称
真的
8.
真的
8.
本地文件
/拉拉/
ffffl_7787
假的
真的
其他
测试类型2
12.9
邮寄
假的
12
128
256
512
真的
0
Trace.Task*
假的
EnableMemorySavingMode
假的
0
0
名称
真的
8.
真的
8.
名称
真的
8.
真的
8.
本地文件
/拉拉/
ffffl_7787
假的
replaceorad.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://www.test.com/xmlns/Test" name="TEST">
    <NVPairs name="Global Variables">
        <NameValuePair>
            <name>Host</name>
            <value>newhost</value>
        </NameValuePair>
        <NameValuePairPassword>
            <name>PasswordDB</name>
            <value>secret</value>
        </NameValuePairPassword>        
    </NVPairs>
    <repoInstances selected="local">
        <localRepoInstance>
            <encoding>UTF-16</encoding>
            <newParameter>ADD_ME</newParameter>
        </localRepoInstance>
    </repoInstances>
    <services>
        <bw name="1.par">
            <enabled>false</enabled>
            <bindings>
                <binding name="1">
                    <machine>testRepo</machine>
                    <product>
                        <type>testtype122</type>
                    </product>
                    <setting>
                        <threadCount>7</threadCount>
                        <java>
                            <initHeapSize>32</initHeapSize>
                            <maxHeapSize>1024</maxHeapSize>
                        </java>
                    </setting>
                    <shutdown>
                        <timeout>7</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>true</value>
                </NameValuePair>
            </NVPairs>
            <checkpoints selected="Local File">
                <checkpoint>Other File</checkpoint>
            </checkpoints>
        </bw>
        <bw name="2.par">
            <enabled>false</enabled>
            <bwprocesses>
                <bwprocess name="process1">
                    <activation>false</activation>
                    <flowLimit>16</flowLimit>
                </bwprocess>
                <bwprocess name="process2">
                    <enabled>false</enabled>
                </bwprocess>                
            </bwprocesses>
            <isFt>true</isFt>
        </bw>       
    </services>
</application>

主办
纽霍斯特
密码数据库
秘密
UTF-16
加上我
假的
测试报告
测试类型122
7.
32
1024
7.
EnableMemorySavingMode
真的
其他文件
假的
假的
16
假的
真的
Output.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://www.test.com/xmlns/Test" name="TEST">
    <repoInstanceName>testRepo</repoInstanceName>
    <NVPairs name="Global Variables">
        <NameValuePair>
            <name>Host</name>
            <value>newhost</value>
        </NameValuePair>
        <NameValuePairInteger>
            <name>Timeout</name>
            <value>60</value>
        </NameValuePairInteger>
        <NameValuePairPassword>
            <name>PasswordDB</name>
            <value>secret</value>
        </NameValuePairPassword>        
    </NVPairs>
    <repoInstances selected="local">
        <localRepoInstance>
            <encoding>UTF-16</encoding>
            <newParameter>ADD_ME</newParameter>
        </localRepoInstance>
    </repoInstances>
    <services>
        <bw name="1.par">
            <enabled>false</enabled>
            <bindings>
                <binding name="1">
                    <machine>testRepo</machine>
                    <product>
                        <type>testtype122</type>
                        <version>12.9</version>
                    </product>
                    <contact>mailme</contact>
                    <setting>
                        <enableVerbose>false</enableVerbose>
                        <threadCount>7</threadCount>
                        <java>
                            <initHeapSize>32</initHeapSize>
                            <maxHeapSize>1024</maxHeapSize>
                            <threadStackSize>512</threadStackSize>
                        </java>
                    </setting>
                    <shutdown>
                        <checkpoint>true</checkpoint>
                        <timeout>7</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>Trace.Task.*</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>true</value>
                </NameValuePair>
            </NVPairs>
            <failureCount>0</failureCount>
            <failureInterval>0</failureInterval>
            <bwprocesses>
                <bwprocess name="process1">
                    <starter>name</starter>
                    <enabled>true</enabled>
                    <maxJob>8</maxJob>
                    <activation>true</activation>
                    <flowLimit>8</flowLimit>
                </bwprocess>
            </bwprocesses>
            <checkpoints selected="Local File">
                <checkpoint>Other File</checkpoint>
                <checkpoint>/lalaa/</checkpoint>
                <tablePrefix>ffffl_7787</tablePrefix>
            </checkpoints>
            <isFt>false</isFt>
        </bw>
        <bw name="2.par">
            <enabled>false</enabled>
            <bindings>
                <binding name="2">
                    <machine>other</machine>
                    <product>
                        <type>testtype2</type>
                        <version>12.9</version>
                    </product>
                    <contact>mailme</contact>
                    <setting>
                        <enableVerbose>false</enableVerbose>
                        <threadCount>12</threadCount>
                        <java>
                            <initHeapSize>128</initHeapSize>
                            <maxHeapSize>256</maxHeapSize>
                            <threadStackSize>512</threadStackSize>
                        </java>
                    </setting>
                    <shutdown>
                        <checkpoint>true</checkpoint>
                        <timeout>0</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>Trace.Task.*</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>false</value>
                </NameValuePair>
            </NVPairs>
            <failureCount>0</failureCount>
            <failureInterval>0</failureInterval>
            <bwprocesses>
                <bwprocess name="process1">
                    <starter>name</starter>
                    <enabled>true</enabled>
                    <maxJob>8</maxJob>
                    <activation>false</activation>
                    <flowLimit>16</flowLimit>
                </bwprocess>
                <bwprocess name="process2">
                    <starter>name</starter>
                    <enabled>false</enabled>
                    <maxJob>8</maxJob>
                    <activation>true</activation>
                    <flowLimit>8</flowLimit>
                </bwprocess>                
            </bwprocesses>
            <checkpoints selected="Local File">
                <checkpoint>Local File</checkpoint>
                <checkpoint>/lalaa/</checkpoint>
                <tablePrefix>ffffl_7787</tablePrefix>
            </checkpoints>
            <isFt>true</isFt>
        </bw>       
    </services>
</application>

测试报告
主办
纽霍斯特
超时
60
密码数据库
秘密
UTF-16
加上我
假的
测试报告
测试类型122
12.9
邮寄
假的
7.
32
1024
512
真的
7.
Trace.Task*
假的
EnableMemorySavingMode
真的
0
0
名称
真的
8.