Created
June 15, 2012 15:50
-
-
Save thoemmi/2937183 to your computer and use it in GitHub Desktop.
PowerShell function to add an XML fragment to an XmlNode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Adds an XML fragment to an XmlNode | |
.DESCRIPTION | |
Adds an XML fragment to an XmlNode | |
.NOTES | |
Author : Thomas Freudenberg - [email protected] | |
.EXAMPLE | |
Add-XmlFragment $xml.configuration.connectionStrings "<add name='MyConString' connectionString='...' providerName='...'>" | |
Adds the connection string "MyConString" to the web.config file. | |
#> | |
function Add-XmlFragment { | |
Param( | |
[Parameter(Mandatory=$true)][System.Xml.XmlNode] $xmlElement, | |
[Parameter(Mandatory=$true)][string] $text) | |
$xml = $xmlElement.OwnerDocument.ImportNode(([xml]$text).DocumentElement, $true) | |
[void]$xmlElement.AppendChild($xml) | |
} |
This realization will not work in case of empty node $xml.configuration.connectionStrings
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent. This works really well!