0

问题如下:

$xml = [xml](Get-Content $USSExternalContentTypeFile)   
$xml.Model.Properties.Property. ....
$xml.Save($USSExternalContentTypeFile)   

名称 类型 #text
---- ---- -----
连接集成安全系统。字符串 textxtxtxtxtxtxt

<Property Name="Connect Integrated Security" Type="System.String">SSPI</Property>

帮助多个xml属性替换#text?

完成:Property[2].'#text' = 'foo'

4

2 回答 2

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
于 2012-04-26T00:28:53.977 回答
1

作为 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.
}
于 2012-04-26T00:58:55.713 回答