简体   繁体   English

Powershell:如何选择和修改Xml评论?

[英]Powershell: how to select and modify Xml comment?

I've got some xml files like below: 我有一些像下面的xml文件:

<?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". 我希望使用powershell来更改这些xml文件:选择注释标签并将“我的注释”更改为“已修改”。

How to do it using XPath or .net xml utility? 如何使用XPath或.net xml实用程序? Thanks a lot. 非常感谢。

Using .net 使用.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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM