问题如下:
$xml = [xml](Get-Content $USSExternalContentTypeFile)
$xml.Model.Properties.Property. ....
$xml.Save($USSExternalContentTypeFile)
名称类型#text
---- ---- -----
Connect Integrated Security System.String textxtxtxtxtxtxtxt
<Property Name="Connect Integrated Security" Type="System.String">SSPI</Property>
帮助多个xml属性替换#text?
完成: 属性[2]。'#text'='foo'
答案 0 :(得分:4)
尝试这种方式来访问#text属性:
PS> $xml = [xml]'<Property Name="Connect Integrated Security" Type="System.String">SSPI</Property> '
PS> $xml.Property
Name Type #text
---- ---- -----
Connect Integrated Security System.String SSPI
PS> $xml.Property.'#text' = 'foo'
PS> $xml.Property
Name Type #text
---- ---- -----
Connect Integrated Security System.String foo
答案 1 :(得分:0)
作为PowerShell的XML节点自动NoteProperties的替代方法,您还可以使用XPath来获取所需的节点。假设您希望所有属性节点的名称属性为“Connect Integrated Security”,您可以使用:
$nodes = $xml.SelectNodes("//Property[@Name='Connect Integrated Security']")
$nodes | % {
$_."#text" = "SomeNewValue" # Changes SSPI to this.
}
如果你想坚持使用NoteProperties,这可能会有效:
$xml.Model.Properties.Property | % {
$_."#text" = "SomeNewValue" # Changes SSPI to this.
}