2012-04-26 4 views
1

属性textxtxtxtxtxtxtPowerShellの編集の#textは問題は以下の通りです

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

#textを置き換えるのに複数のxml属性を使用できますか?

フィニッシュ:XMLのためのPowerShellの自動NotePropertiesする代わりに

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

'$ xに= [xml] ' hello' – jjee

+0

'$ x.SelectSingleNode( 'name')。 '#text' = 'world'' – jjee

答えて

2

の#textプロパティにアクセスするには、この方法を試してみてください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

これは動作しません! $ xml = [xml](Get-Content $ USSExternalContentTypeFile) $ xml.Model.Properties.Property。 .... $ xml.Save($ USSExternalContentTypeFile) –

+0

$ xml.Model.Properties.Property |ここで{$ _。Name -eq "Connect Integrated Security"} –

+0

プロパティ[2]。 '#text' –

0

: プロパティ[2] '#テキスト' = 'foo' で

+0

終了: プロパティ[2]。 '#text' = 'foo' –

関連する問題