4

I've got some xml files like below:

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <ItemGroup>
    <Book Name="Learn Powershell" />
    <Book Name=".net Programming" />
    <Book Name="C# Programming" />
  </ItemGroup>
  <!--
    my comments
    -->
</Project>

I wish to use powershell to changes these xml files: select the comment tags and change "my comments" into "modified".

How to do it using XPath or .net xml utility? Thanks a lot.

1 Answer 1

4

Using .net

[xml]$x=get-content file.xml 
$x.Project."#comment"="modified"          
$x.Save("c:\newxml.xml")   

another option using replace

(get-content file.xml).Replace("my comments","modified") |out-file newxml.xml 
Sign up to request clarification or add additional context in comments.

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.