0

I have 2 XML files
First XML file :

<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>

Second XML file :

<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>

i want to take all the child nodes under metaDataSet and move them from one file to another

i got a bit lost with the XML functions in powershell any direction will be welcomed

thanks !

1
  • Which child nodes? Which xml functions have you tried? Commented Feb 19, 2018 at 18:56

2 Answers 2

3

solved it

$ENV:workspace="C:\TEMP\XMLTRANS\" $from = [xml](Get-Content $env:workspace\from.xml) $to = [xml](Get-Content $env:workspace\from2.xml) foreach ($node in $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')

hope it will help someone :)

Sign up to request clarification or add additional context in comments.

Comments

0

I was working on a blog post about adding an XML node into a config, which might help you here. Here is the snippit:

$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")

Your $newNode will just need to come from the properties of the other file by looping over child nodes.

Hope that helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.