我试图从XML标记访问和更改特定属性
XML:
<office>
<staff branch="Hanover" Type="sales">
<employee>
<Name>Tobias Weltner</Name>
<function>management</function>
<age>39</age>
</employee>
<employee>
<Name>Cofi Heidecke</Name>
<function>security</function>
<age>4</age>
</employee>
</staff>
<staff branch="London" Type="Technology">
<employee>
<Name>XXXX</Name>
<function>gement</function>
<age>39</age>
Run Code Online (Sandbox Code Playgroud)
从上面的例子我想打印分支属性,然后想要在所有整个XML中使用一个值(如纽约)更改它,并使用下面的代码来执行该操作
$xml=New-Object XML
$xml.Load("C:\FE6Work.xml")
$node=$xml.SelectNodes("/office/staff")
write-output $node.branch
$node.branch="New York"
Run Code Online (Sandbox Code Playgroud)
但得到一个错误说明无法找到该元素.
有人可以帮忙吗?
我试图使用下面的PowerShell代码从包含部分字符串的文本文件中删除所有行:
Get-Content C:\new\temp_*.txt | Select-String -pattern "H|159" -notmatch | Out-File C:\new\newfile.txt
Run Code Online (Sandbox Code Playgroud)
实际的字符串是H|159|28-05-2005|508|xxx,它在文件中重复多次,我试图只匹配上面指定的第一部分.那是对的吗?目前我的输出是空的.
我错过了什么吗?