Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4077464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:33:13+00:00 2026-05-20T17:33:13+00:00

I have two XML files (File1.xml, File2.xml). File2.xml is a subset of File1.xml. File1.xml

  • 0

I have two XML files (File1.xml, File2.xml). File2.xml is a subset of File1.xml.

File1.xml has nodes like so:

<parentnode>
    <item id="GUID1">
         <Text>Some Text</Text> 
    </item>
    <item id="GUID2">
        <Text>Here’s some more text</Text> 
    </item>
</parentnode>

File2.xml has:

<parentnode>
    <item id="GUID1">
         <Text>Some Replacement Text</Text> 
    </item>
</parentnode>

I want to take the item with GUIDx in File1.xml, and replace it with the item with GUIDx from File2.xml. Essentially, I want to take the replacement text in File2.xml and insert it into the corresponding item node in File1.xml

How do I do this in PowerShell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:33:13+00:00Added an answer on May 20, 2026 at 5:33 pm

    Suppose I have first xml in variable $edited and the second in $new. Then you can change value in item with id GUID1 via

    $edited.parentnode.item | 
       ? { $_.id -eq 'guid1' } | 
       % { $_.Text = $new.parentnode.item.Text }
    # and save the file
    $edited.Save('d:\File1.xml')
    # see the changes
    gc d:\File1.xml
    

    In case you have more items to replace, you could use nested pipelines:

    $edited = [xml]@"
    <parentnode>
        <item id="GUID1"><Text>Some Text</Text></item>
        <item id="GUID2"><Text>Here’s some more text</Text></item>
        <item id="GUID3"><Text>Here’s some more text</Text></item>
        <item id="GUID10"><Text>Here’s some more text</Text></item>
    </parentnode>
    "@
    $new = [xml] @"
    <parentnode>
        <item id="GUID1"><Text>new Guid1</Text></item>
        <item id="GUID2"><Text>new Guid2</Text></item>
        <item id="GUID3"><Text>new Guid3</Text></item>
        <item id="GUID4"><Text>new Guid4</Text></item>
        <item id="GUID5"><Text>new Guid5</Text></item>
    </parentnode>
    "@
    $new.parentnode.item | 
        % { ,($_.id,$_.Text)} | 
        % { $id,$text = $_; 
            $edited.parentnode.item | 
               ? { $_.id -eq $id } | 
               % { $_.Text = $text }
        }
    

    or foreach cycle which is more readable here:

    foreach($i in $new.parentnode.item) { 
        $edited.parentnode.item | 
               ? { $_.id -eq $i.Id } | 
               % { $_.Text = $i.Text }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two XML files. They are similar, but there are two nodes of
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I have two files, file1 and file2. I have to modify file1 in a
I have two files file a.) xmlFile.xml b.) emails.txt xmlFile.xml has the following structure
I have two xml files, one of them is dev.xml which has this code
I have two XML files with two different XSD schemas and different namespaces. They
Are there any tools to effectively compare two XML schema's? I have seen some
I have two xml files but one file will contain an extra field. Ideally
I have two XML files to render one page in XSLT. This is because
I have built two XML files that map the content of a given folder:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.