Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/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中的2个XML之间复制子节点_Xml_Powershell - Fatal编程技术网

在powershell中的2个XML之间复制子节点

在powershell中的2个XML之间复制子节点,xml,powershell,Xml,Powershell,我有2个XML文件 第一个XML文件: <task> <name/> <transfer> <request version="6.00" xsi:noNamespaceSchemaLocation="FileTransfer.xsd"> <managedTransfer> <originator> <hostName>host.corp.</

我有2个XML文件
第一个XML文件:

<task>
  <name/>
  <transfer>
    <request version="6.00" xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
      <managedTransfer>
        <originator>
          <hostName>host.corp.</hostName>
          <userID>jenkins</userID>
        </originator>
        <sourceAgent QMgr="${SourceQm}" agent="${SourceAgent}"/>
        <destinationAgent QMgr="${DestQm}" agent="${DestAgent}"/>
        <transferSet priority="0">
          <metaDataSet>
            <metaData key="site">${MdSite}</metaData>
            <metaData key="businessSourceSystem">${MdSourceSystem}</metaData>
            <metaData key="businessTargetSystem">${MdTargetSystem}</metaData>
            <metaData key="wricef">${MdWricef}</metaData>
          </metaDataSet>
        </transferSet>
        <job>
          <name>${MonitorName}</name>
        </job>
      </managedTransfer>
    </request>
  </transfer>
</task>

主机公司。
詹金斯
${MdSite}
${MdSourceSystem}
${MdTargetSystem}
${MdWricef}
${MonitorName}

第二个XML文件:

<task>
  <name/>
  <transfer>
    <request version="6.00" xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
      <managedTransfer>
        <originator>
          <hostName>HOST.corp</hostName>
          <userID>jenkins</userID>
        </originator>
        <sourceAgent QMgr="${SourceQm}" agent="${SourceAgent}"/>
        <destinationAgent QMgr="${DestQm}" agent="${DestAgent}"/>
        <transferSet priority="0">
        </transferSet>
        <job>
          <name>${MonitorName}</name>
        </job>
      </managedTransfer>
    </request>
  </transfer>
</task>

主机公司
詹金斯
${MonitorName}

我想获取metaDataSet下的所有子节点,并将它们从一个文件移动到另一个文件

我对powershell中的XML函数有点迷茫 任何方向都将受到欢迎


谢谢

我在写一篇关于在配置中添加XML节点的博文,这可能会对您有所帮助。这是一个小笑话:

$global:pathToConfig = "$PSScriptRoot\DistributedCacheService.exe.config" #put your path here

#force the config into an XML
$xml = [xml](get-content $pathToConfig)

#build new node by hand and force it to be an XML object
$newNode = [xml]@"
<appSettings>
 <add key="backgroundGC" value="true"/>
</appSettings>
"@

#add new node AFTER the configsections node
$xml.configuration.InsertAfter($xml.ImportNode($newNode.appSettings, $true), $xml.configuration.configsections)

#save file
$xml.Save("$pathToConfig.CHANGED.XML")
$global:pathToConfig=“$PSScriptRoot\DistributedCacheService.exe.config”#将路径放在这里
#将配置强制转换为XML
$xml=[xml](获取内容$pathToConfig)
#手动构建新节点并强制它成为XML对象
$newNode=[xml]@”
"@
#在configsections节点之后添加新节点
$xml.configuration.InsertAfter($xml.ImportNode($newNode.appSettings,$true),$xml.configuration.configsections)
#保存文件
$xml.Save(“$pathToConfig.CHANGED.xml”)
您的
$newNode
只需要通过在子节点上循环来获取另一个文件的属性


希望有帮助

我在写一篇关于在配置中添加XML节点的博文,这可能会对您有所帮助。这是一个小笑话:

$global:pathToConfig = "$PSScriptRoot\DistributedCacheService.exe.config" #put your path here

#force the config into an XML
$xml = [xml](get-content $pathToConfig)

#build new node by hand and force it to be an XML object
$newNode = [xml]@"
<appSettings>
 <add key="backgroundGC" value="true"/>
</appSettings>
"@

#add new node AFTER the configsections node
$xml.configuration.InsertAfter($xml.ImportNode($newNode.appSettings, $true), $xml.configuration.configsections)

#save file
$xml.Save("$pathToConfig.CHANGED.XML")
$global:pathToConfig=“$PSScriptRoot\DistributedCacheService.exe.config”#将路径放在这里
#将配置强制转换为XML
$xml=[xml](获取内容$pathToConfig)
#手动构建新节点并强制它成为XML对象
$newNode=[xml]@”
"@
#在configsections节点之后添加新节点
$xml.configuration.InsertAfter($xml.ImportNode($newNode.appSettings,$true),$xml.configuration.configsections)
#保存文件
$xml.Save(“$pathToConfig.CHANGED.xml”)
您的
$newNode
只需要通过在子节点上循环来获取另一个文件的属性

希望有帮助

解决了它

$ENV:workspace=“C:\TEMP\XMLTRANS”
$from=[xml](获取内容$env:workspace\from.xml)
$to=[xml](获取内容$env:workspace\from2.xml)
foreach($from.tasks.task.transfer.request.managedTransfer.transferSet.metaDataSet中的节点){
$to.tasks.task.transfer.request.managedTransfer.transferSet.AppendChild($to.ImportNode($node,$true))}
$to.Save('C:\TEMP\XMLTRANS\last1.xml')

希望它能帮助某人:)

解决了它

$ENV:workspace=“C:\TEMP\XMLTRANS”
$from=[xml](获取内容$env:workspace\from.xml)
$to=[xml](获取内容$env:workspace\from2.xml)
foreach($from.tasks.task.transfer.request.managedTransfer.transferSet.metaDataSet中的节点){
$to.tasks.task.transfer.request.managedTransfer.transferSet.AppendChild($to.ImportNode($node,$true))}
$to.Save('C:\TEMP\XMLTRANS\last1.xml')


希望对某人有所帮助:)

哪个子节点?您尝试过哪些xml函数?哪些子节点?您尝试过哪些xml函数?