6

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

Content of rules.xml:

<file folder="" filename="Rules" object="ArrayOfIBarcodeRule">
  <Profile name="Test471">
    <IBarcodeRule>
      <RuleName>DOC-TESTTESTTEST-Code128</RuleName>
      <FieldSequenceNumber>1</FieldSequenceNumber>
      <FieldRectangle>
        <Location>
          <X>0</X>
          <Y>0</Y>
        </Location>
        <Size>
          <Width>0</Width>
          <Height>0</Height>
        </Size>
      </FieldRectangle>
      <SeparationValue>TESTTESTTEST</SeparationValue>
    </IBarcodeRule>
  </Profile>
</file>

I am trying to add the entire contents of rules.xml (the file node) as another node in profile.xml. As you can see, there are a bunch of other file nodes in the profile.xml, and the rules.xml would be another one.

This is the code I have tried, and it does not seem to do anything:

$xml = [xml](Get-Content ".\profile.xml")
$newxml = [xml](Get-Content ".\rules.xml")
$xml.ImportNode($newxml.get_DocumentElement(), $true)
$xml.Save(".\profile.xml")

2 Answers 2

15

You're really close but ImportNode only makes a copy and doesn't actually insert the copied nodes into the document. Try this:

$newNode = $newxml.ImportNode($xml.get_DocumentElement(), $true)
$newxml.DocumentElement.AppendChild($newNode)
$xml.Save("$pwd\profile.xml")  
Sign up to request clarification or add additional context in comments.

Comments

-2

Content of 1.xml

<files><file>123</file><file>456</file><br></files>

Content of 2.xml

<file>789</file>

Powershell:

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

This Works fine for me

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.