0
我需要組合幾個XML文件,並告訴這部分屬於每個文件的XML。以下是這些文件的兩個例子。結合XML文件和「稱號」每節
d:\ pathtoxml \ 1.XML
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<section name="name" type="theres stuff here" />
</configSections>
<appSettings>
<add key="key1" value="valueOfKey1" />
</appSettings>
</configuration>
d:\ pathtoxml \ 2.XML
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings>
<add key="key1" value="valueofkey1" />
</appSettings>
<connectionStrings>
<add name="connectionstring1" connectionString="connectionstringstuff" />
</connectionStrings>
</configuration>
最終文件需要這個樣子
<WebConfigs>
<path = 'D:\pathtoxml\1.xml'>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<section name="name" type="theres stuff here" />
</configSections>
<appSettings>
<add key="key1" value="valueOfKey1" />
</appSettings>
</configuration>
</path>
<path = 'D:\pathtoxml\2.xml'>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings>
<add key="key1" value="valueofkey1" />
</appSettings>
<connectionStrings>
<add name="connectionstring1" connectionString="connectionstringstuff" />
</connectionStrings>
</configuration>
</path>
</WebConfigs>
我當前的代碼看起來是這樣的,但是我得到的各種XML錯誤
$path1 = 'D:\pathtoxml\1.xml'
$path2 = 'D:\pathtoxml\2.xml'
$exportPath = 'D:\exportPath\combined.xml'
$finalXml = "<path = '" + $path1 + "'>"
[xml]$xml = get-content $path1
$finalXml += $xml.InnerXml
$finalXml += "</path>"
$finalXml += "<path = '" + $path1 + "'>"
[xml]$xml = get-content $path2
$finalXml += $xml.InnerXml
$finalXml += "</path>"
([xml]$finalXml).Save($exportPath)
我發現this question但它並沒有解決增加的方式合併文件,每個文件來源是告訴。
你爲什麼不告訴我們第一本 「各種XML的錯誤」 的是,我們可以着手解決這個問題。 – LarsH