使用Java合并多个XML文件

时间:2014-07-12 06:11:05

标签: java xml

我有一个代码来合并两个xml文件,但我预期的结果是不同的。

XML 1:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="unit.qa.fm" tests="14" time="3182.09">
<properties/>
<testcase classname="com.ca.clarity.unit.financial.transaction.CBKRuleForAllFTP42249QAUTest" name="invoiceAdjustments" testCaseID="42249" time="175.548"/>
<testcase classname="com.ca.clarity.unit.financial.transaction.CreateWIPAdjustmentChangingRateReflectInInvoice42207QAUTest" name="invoiceAdjustments42207" testCaseID="42207" time="171.971"/>
</testsuite>

XML 2:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="unit.qa.fm" tests="10" time="1647.807">
<properties/>
<testcase classname="com.ca.clarity.unit.financial.setup.CheckDepartmentAndDepartmentOBSAreInSync58786QAUTest" name="CheckDeptAndDeptOBSAreInSync" testCaseID="58786" time="27.132"/>
<testcase classname="com.ca.clarity.unit.financial.setup.DepartmentXogQAUTest" name="validateDepartmentXogIn" testCaseID="52082" time="11.097"/>
</testsuite>

预期结果:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><testsuite errors="0" failures="0" name="unit.qa.fm" tests="14" time="3182.09">
  <properties/>
  <testcase classname="com.ca.clarity.unit.financial.transaction.CBKRuleForAllFTP42249QAUTest" name="invoiceAdjustments" testCaseID="42249" time="175.548"/>
  <testcase classname="com.ca.clarity.unit.financial.transaction.CreateWIPAdjustmentChangingRateReflectInInvoice42207QAUTest" name="invoiceAdjustments42207" testCaseID="42207" time="171.971"/>
  <testcase classname="com.ca.clarity.unit.financial.setup.CheckDepartmentAndDepartmentOBSAreInSync58786QAUTest" name="CheckDeptAndDeptOBSAreInSync" testCaseID="58786" time="27.132"/>
  <testcase classname="com.ca.clarity.unit.financial.setup.DepartmentXogQAUTest" name="validateDepartmentXogIn" testCaseID="52082" time="11.097"/>
</testsuite>

实际我正在

<?xml version="1.0" encoding="UTF-8" standalone="no"?><testsuite errors="0" failures="0" name="unit.qa.fm" tests="14" time="3182.09">
  <properties/>
  <testcase classname="com.ca.clarity.unit.financial.transaction.CBKRuleForAllFTP42249QAUTest" name="invoiceAdjustments" testCaseID="42249" time="175.548"/>
  <testcase classname="com.ca.clarity.unit.financial.transaction.CreateWIPAdjustmentChangingRateReflectInInvoice42207QAUTest" name="invoiceAdjustments42207" testCaseID="42207" time="171.971"/>
  <testcase classname="com.ca.clarity.unit.financial.setup.CheckDepartmentAndDepartmentOBSAreInSync58786QAUTest" name="CheckDeptAndDeptOBSAreInSync" testCaseID="58786" time="27.132"/>
  <testcase classname="com.ca.clarity.unit.financial.setup.DepartmentXogQAUTest" name="validateDepartmentXogIn" testCaseID="52082" time="11.097"/>
</testsuite><?xml version="1.0" encoding="UTF-8" standalone="no"?><testsuite errors="0" failures="0" name="unit.qa.fm" tests="10" time="1647.807">
  <properties/>
  <testcase classname="com.ca.clarity.unit.financial.setup.CheckDepartmentAndDepartmentOBSAreInSync58786QAUTest" name="CheckDeptAndDeptOBSAreInSync" testCaseID="58786" time="27.132"/>
  <testcase classname="com.ca.clarity.unit.financial.setup.DepartmentXogQAUTest" name="validateDepartmentXogIn" testCaseID="52082" time="11.097"/>
</testsuite>

任何人都可以帮助我只将testcase节点添加到现有XML文件而不是整个内容。

谢谢,

0 个答案:

没有答案