2012-04-26 77 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