2012-04-26 76 views
1

的问题如下:PowerShell的编辑#text属性

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

名称类型#text
---- ---- -----
连接集成安全System.String textxtxtxtxtxtxt

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

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

完成: 属性[2] '#文字'= '富'

+0

'$ X = [XML] '你好 ''' – jjee 2016-05-26 10:23:40

+0

$ x.SelectSingleNode(' 名 ')。' #文字'=“world'' – jjee 2016-05-26 10:23:51

回答

2

尝试这种方式来访问#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 
+0

这不行! $ xml = [xml](Get-Content $ USSExternalContentTypeFile) $ xml.Model.Properties.Property。 ... $ xml.Save($ USSExternalContentTypeFile) – 2012-04-26 00:46:40

+0

$ xml.Model.Properties.Property |其中{$ _名称-eq “连接集成安全性”。} – 2012-04-26 00:50:50

+0

属性[2] '#文本' – 2012-04-26 01:00:30

0

作为替代PowerShell中对XML的自动NoteProperties节点也可以使用XPath来获取所需的节点。如果你想与“连接集成安全性”的name属性的属性节点说,你可以使用:

$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. 
} 
+0

表面处理: 属性[2] '#文字'= '富' – 2012-04-26 01:02:34