T
T
TechNOIR2020-03-30 19:40:04
PowerShell
TechNOIR, 2020-03-30 19:40:04

powershell+xml. How to convert an XML block from one file to the form of another file?

Good afternoon.
With the help of Powershell I want to automate the mass change of xml templates.
There are 2 files that have the same structure but different controls and you need to bring them to a common view.
file1.xml is the reference. it is necessary to bring the contents of the Tester group in file2.xml to the form of the standard.

How to do it right? ReplaceChild or clear the group first and then the ImportNode?

Thanks a lot in advance for your help

#file1.xml
<?xml version="1.0" encoding="utf-8"?>
<FORM>
<Group>
  <Column PercentWidth="20">
    <Group Label="Tester">
      <Column PercentWidth="100">
            <Control FieldName="Microsoft.VSTS.Scheduling.StoryPoints" Type="FieldControl" Label="Label1" LabelPosition="Left" />
            <Control FieldName="Microsoft.VSTS.Common.Priority" Type="FieldControl" Label="Label2" LabelPosition="Left" />
            <Control FieldName="Microsoft.VSTS.Common.Severity" Type="FieldControl" Label="Label3" LabelPosition="Left" />
      </Column>
    </Group>
  </Column>
</Group>
</FORM>


#file2.xml
<?xml version="1.0" encoding="utf-8"?>
<FORM>
<Group>
  <Column PercentWidth="20">
    <Group Label="Tester">
      <Column PercentWidth="100">
      <Control FieldName="Microsoft.VSTS.Common.Severity" Type="FieldControl" Label="Label1" LabelPosition="Left" />
      <Control FieldName="Microsoft.VSTS.Common.Priority" Type="FieldControl" Label="Label2" LabelPosition="Left" />
      <Control FieldName="Microsoft.VSTS.Scheduling.StoryPoints" Type="FieldControl" Label="Label4" LabelPosition="Left" />
      </Column>
    </Group>
  </Column>
</Group>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2020-03-30
@MaxKozlov

It is completely unclear what is meant by ".... but different controls and it is necessary to bring them to a common view."
Do you mean the order of the "FieldName" elements, the Label numbers or something else?
Or do we need to completely replace the contents of Group ?
For example like this

$x1 = [xml]$xml1
$x2 = [xml]$xml2
$x2.FORM.Group.InnerXml = $x1.FORM.Group.InnerXml
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question