-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert-XmlFile.html
177 lines (154 loc) · 8.21 KB
/
Convert-XmlFile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PowerShell - Convert-XmlFile - Carbon</title>
<link href="silk.css" type="text/css" rel="stylesheet" />
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body>
<ul id="SiteNav">
<li><a href="index.html">Get-Carbon</a></li>
<li><a href="about_Carbon_Installation.html">-Install</a></li>
<li><a href="documentation.html">-Documentation</a></li>
<li><a href="about_Carbon_Support.html">-Support</a></li>
<li><a href="releasenotes.html">-ReleaseNotes</a></li>
<li><a href="http://pshdo.com">-Blog</a></li>
<li><a href="https://github.com/webmd-health-services/Carbon/">-Project</a></li>
</ul>
<h1>Convert-XmlFile</h1>
<div class="Synopsis">
<p>Transforms an XML document using XDT (XML Document Transformation).</p>
</div>
<h2>Syntax</h2>
<pre class="Syntax"><code>Convert-XmlFile -Path <String> -XdtPath <String> -Destination <String> [-TransformAssemblyPath <String[]>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
</code></pre>
<pre class="Syntax"><code>
</code></pre>
<pre class="Syntax"><code>Convert-XmlFile -Path <String> -XdtXml <XmlDocument> -Destination <String> [-TransformAssemblyPath <String[]>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]</code></pre>
<h2>Description</h2>
<div class="Description">
<p>An XDT file specifies how to change an XML file from a <em>known</em> beginning state into a new state. This is usually helpful when deploying IIS websites. Usually, the website's default web.config file won't work in different environments, and needs to be changed during deployment to reflect settings needed for the target environment.</p>
<p>XDT was designed to apply a tranformation against an XML file in a <em>known</em> state. <strong>Do not use this method to transform an XML file in-place.</strong> There lies madness, and you will never get that square peg into XDT's round hole. If you <em>really</em> want to transform in-place, you're responsible for checking if the source/destination file has already been transformed, and if it hasn't, calling <code>Convert-XmlFile</code> to transform to a temporary file, then copying the temporary file onto the source/destination file.</p>
<p>You can load custom transformations. In your XDT XML, use the <code>xdt:Import</code> element to import your transformations. In your XDT file:</p>
<pre><code><?xml version="1.0"?>
<root xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- You can also use the "assembly" attribute (PowerShell v3
*only*). In PowerShell v2, you can only use the `path`
attribute.
All classes in `namespace` that inherit from the XDT
`Transform` class are loaded. -->
<xdt:Import path="C:\Projects\Carbon\Lib\ExtraTransforms.dll"
namespace="ExtraTransforms" />
<!-- ...snip... -->
</root>
</code></pre>
<p>You also have to pass the path to your custom transformation assembly as a value to the <code>TransformAssemblyPath</code> parameter. That's it! (Note: Carbon does <em>not</em> ship with any extra transformations.)</p>
<p>When transforming a file, the XDT framework will write warnings and errors to the PowerShell error and warning stream. Informational and debug messages are written to the verbose stream (i.e. use the <code>Verbose</code> switch to see all the XDT log messages).</p>
</div>
<h2>Related Commands</h2>
<ul class="RelatedCommands">
<li><a href="http://msdn.microsoft.com/en-us/library/dd465326.aspx">http://msdn.microsoft.com/en-us/library/dd465326.aspx</a></li>
<li><a href="http://stackoverflow.com/questions/2915329/advanced-tasks-using-web-config-transformation">http://stackoverflow.com/questions/2915329/advanced-tasks-using-web-config-transformation</a></li>
<li><a href="Set-DotNetConnectionString.html">Set-DotNetConnectionString</a></li>
<li><a href="Set-DotNetAppSetting.html">Set-DotNetAppSetting</a></li>
</ul>
<h2> Parameters </h2>
<table id="Parameters">
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required?</th>
<th>Pipeline Input</th>
<th>Default Value</th>
</tr>
<tr valign='top'>
<td>Path</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String</a></td>
<td class="ParamDescription"><p>The path of the XML file to convert.</p></td>
<td>true</td>
<td>false</td>
<td></td>
</tr>
<tr valign='top'>
<td>XdtPath</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String</a></td>
<td class="ParamDescription"><p>The path to the XDT file.</p></td>
<td>true</td>
<td>false</td>
<td></td>
</tr>
<tr valign='top'>
<td>XdtXml</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx">XmlDocument</a></td>
<td class="ParamDescription"><p>The raw XDT XML to use.</p></td>
<td>true</td>
<td>false</td>
<td></td>
</tr>
<tr valign='top'>
<td>Destination</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String</a></td>
<td class="ParamDescription"><p>The destination XML file's path.</p></td>
<td>true</td>
<td>false</td>
<td></td>
</tr>
<tr valign='top'>
<td>TransformAssemblyPath</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String[]</a></td>
<td class="ParamDescription"><p>List of assemblies to load which contain custom transforms.</p></td>
<td>false</td>
<td>false</td>
<td>@()</td>
</tr>
<tr valign='top'>
<td>Force</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.management.automation.switchparameter.aspx">SwitchParameter</a></td>
<td class="ParamDescription"><p>Overwrite the destination file if it exists.</p></td>
<td>false</td>
<td>false</td>
<td>False</td>
</tr>
<tr valign='top'>
<td>WhatIf</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.management.automation.switchparameter.aspx">SwitchParameter</a></td>
<td class="ParamDescription"></td>
<td>false</td>
<td>false</td>
<td></td>
</tr>
<tr valign='top'>
<td>Confirm</td>
<td><a href="http://msdn.microsoft.com/en-us/library/system.management.automation.switchparameter.aspx">SwitchParameter</a></td>
<td class="ParamDescription"></td>
<td>false</td>
<td>false</td>
<td></td>
</tr>
<tr valign="top">
<td><a href="http://technet.microsoft.com/en-us/library/dd315352.aspx">CommonParameters</a></td>
<td></td>
<td>This cmdlet supports common parameters. For more information type <br> <code>Get-Help about_CommonParameters</code>.</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<h2>EXAMPLE 1</h2>
<pre><code>Convert-XmlFile -Path ".\web.config" -XdtPath ".\web.debug.config" -Destination '\\webserver\wwwroot\web.config'</code></pre>
<p>Transforms <code>web.config</code> with the XDT in <code>web.debug.config</code> to a new file at <code>\\webserver\wwwroot\web.config</code>.</p>
<h2>EXAMPLE 2</h2>
<pre><code><connectionStrings><add name=""MyConn"" xdt:Transform=""Insert"" /></connectionStrings></configuration>" -Destination '\\webserver\wwwroot\web.config'</code></pre>
<p>Transforms <code>web.config</code> with the given XDT XML to a new file at <code>\\webserver\wwwroot\web.config</code>.</p>
<h2>EXAMPLE 3</h2>
<pre><code>Convert-XmlFile -Path ".\web.config" -XdtPath ".\web.debug.config" -Destination '\\webserver\wwwroot\web.config' -Verbose</code></pre>
<p>See that <code>Verbose</code> switch? It will show informational/debug messages written by the XDT framework. Very helpful in debugging what XDT framework is doing.</p>
<h2>EXAMPLE 4</h2>
<pre><code>Convert-XmlFile -Path ".\web.config" -XdtPath ".\web.debug.config" -Destination '\\webserver\wwwroot\web.config' -TransformAssemblyPath C:\Projects\CustomTransforms.dll</code></pre>
<p>Shows how to reference a custom transformation assembly. It should also be loaded in your XDT file via the <code>xdt:Import</code>.</p>
<div class="Footer">
Copyright 2012 - 2018 <a href="http://pshdo.com">Aaron Jensen</a>.
</div>
</body>
</html>