1
我與此處的問題相同:What is the fastest way to combine two xml files into one 不幸的是,這裏給出的答案效果不佳。將兩個XML文件合併到一個文件中
我有完全相同的問題。 我有兩個文件:
XML1:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Results>
<Memory>
<instance00>
<PageFaultsPersec>
<sample time="9/8/2016 12:02:51 PM" value="1401.112" />
<sample time="9/8/2016 12:02:52 PM" value="242.3494" />
<sample time="9/8/2016 12:02:53 PM" value="303.1362" />
</PageFaultsPersec>
<AvailableBytes>
<sample time="9/8/2016 12:02:51 PM" value="1.116967E+09" />
<sample time="9/8/2016 12:02:52 PM" value="1.11702E+09" />
<sample time="9/8/2016 12:02:53 PM" value="1.11761E+09" />
</AvailableBytes>
</instance00>
</Memory>
</Results>
XML2:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Results>
<Processor>
<instance_Total>
<PercentProcessorTime>
<sample time="9/8/2016 12:02:51 PM" value="18.4567" />
<sample time="9/8/2016 12:02:52 PM" value="3.032005" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentProcessorTime>
<PercentUserTime>
<sample time="9/8/2016 12:02:51 PM" value="17.04996" />
<sample time="9/8/2016 12:02:52 PM" value="3.03025" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentUserTime>
<PercentPrivilegedTime>
<sample time="9/8/2016 12:02:51 PM" value="0.7413027" />
<sample time="9/8/2016 12:02:52 PM" value="0" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentPrivilegedTime>
</instance_Total>
</Processor>
</Results>
我想:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Results>
<Memory>
<instance00>
<PageFaultsPersec>
<sample time="9/8/2016 12:02:51 PM" value="1401.112" />
<sample time="9/8/2016 12:02:52 PM" value="242.3494" />
<sample time="9/8/2016 12:02:53 PM" value="303.1362" />
</PageFaultsPersec>
<AvailableBytes>
<sample time="9/8/2016 12:02:51 PM" value="1.116967E+09" />
<sample time="9/8/2016 12:02:52 PM" value="1.11702E+09" />
<sample time="9/8/2016 12:02:53 PM" value="1.11761E+09" />
</AvailableBytes>
</instance00>
</Memory>
<Processor>
<instance_Total>
<PercentProcessorTime>
<sample time="9/8/2016 12:02:51 PM" value="18.4567" />
<sample time="9/8/2016 12:02:52 PM" value="3.032005" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentProcessorTime>
<PercentUserTime>
<sample time="9/8/2016 12:02:51 PM" value="17.04996" />
<sample time="9/8/2016 12:02:52 PM" value="3.03025" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentUserTime>
<PercentPrivilegedTime>
<sample time="9/8/2016 12:02:51 PM" value="0.7413027" />
<sample time="9/8/2016 12:02:52 PM" value="0" />
<sample time="9/8/2016 12:02:53 PM" value="0" />
</PercentPrivilegedTime>
</instance_Total>
</Processor>
</Results>
正如我所說的,我想答案,那名在鏈接中給出,但其中一些根本不起作用,有些只是加入兩個文件而沒有正確放置子元素。
XML文件是磁盤上的真實文件,而不僅僅是字符串。
我不認爲這可以在一般的方式,來完成作爲給現有的XML文件,併合並文檔,也沒有辦法知道是否重複節點必須遞歸合併,或作爲數組附加。 –