Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
来自不同文件的Powershell XML导入节点_Xml_Powershell - Fatal编程技术网

来自不同文件的Powershell XML导入节点

来自不同文件的Powershell XML导入节点,xml,powershell,Xml,Powershell,profile.xml的内容: <files> <file folder="CaptureServer" filename="CSConfig" object="CSConfig"> <Profile name="BBH1200Kofax"> <OutputCache>\</OutputCache> <EncryptedConnectionString>564rgr=</Encryp

profile.xml的内容:

<files>
  <file folder="CaptureServer" filename="CSConfig" object="CSConfig">
    <Profile name="BBH1200Kofax">
      <OutputCache>\</OutputCache>
      <EncryptedConnectionString>564rgr=</EncryptedConnectionString>
      <ConvertDocsBeforeRelease>false</ConvertDocsBeforeRelease>
    </Profile>
  </file>
  <file folder="CaptureServices3" filename="CSConfig" object="CSConfig">
    <Profile name="BBH1200Kofax">
      <ReleaseToEnterprise>true</ReleaseToEnterprise>
      <CaptureServerUrl />
      <OutputCache />
      <Credentials>
        <EncryptedPassword>46s4rg=</EncryptedPassword>
        <UserName />
        <Domain />
      </Credentials>
      <ConvertDocsBeforeRelease>false</ConvertDocsBeforeRelease>
    </Profile>
  </file>
</files>

您已经非常接近了,但ImportNode只创建了一个副本,实际上并没有将复制的节点插入到文档中。试试这个:

$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true)
$newxml.DocumentElement.AppendChild($newNode)
$xml.Save("$pwd\profile.xml")  
1.xml的内容

<files><file>123</file><file>456</file><br></files>
这对我来说很好

$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true)
$newxml.DocumentElement.AppendChild($newNode)
$xml.Save("$pwd\profile.xml")  
<files><file>123</file><file>456</file><br></files>
<file>789</file>
$oXML = [xml](Get-Content "1.xml")
$oNewXml = [xml](Get-Content "2.xml")
$oNewNode = $oXML.ImportNode($oNewXml.get_DocumentElement(), $true)
$oXML.DocumentElement.AppendChild($oNewNode)
$oXML.Save("3.xml")