I have been stuck on this from a week where I am trying to append a XML node to a parent XML element. the child node and the parent node look like this :
[xml]$childxml = @"
<ClaimsProvider>
<Bomain> hey there</Bomain>
<Name>Login using </Name>
<TechnicalProfiles>
<TechnicalProfile Id="MIDC-What">
<DisplayName> Employee</DisplayName>
<Description>Login with your account</Description>
<Protocol Name="OpenIdConnect" />
<Metadata>
<Item Key="METADATA">https://login.microsoftonline.com</Item>
<Item Key="client_id">Mangal</Item>
<Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com</Item>
</Metadata>
<Cryptograph>
<Key Id="client_secret" StorageReferenceId="key" />
</Cryptograph>
<IncludeTechnicalProfile ReferenceId="MIDC-Shared" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
"@
And I want to add this child node to this file (filename: permissions.xml
)
<TrustFrameworkPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"">
<BasePolicy>
</BasePolicy>
<BuildingBlocks></BuildingBlocks>
<ClaimsProviders>
<ClaimsProvider>
<Bomain> hey there 1</Bomain>
<Name>Login using </Name>
<TechnicalProfiles>
<TechnicalProfile Id="MIDC-What">
<DisplayName> Employee</DisplayName>
<Description>Login with your account</Description>
<Protocol Name="OpenIdConnect" />
<Metadata>
<Item Key="METADATA">https://login.microsoftonline.com</Item>
<Item Key="client_id">Mangal</Item>
<Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com</Item>
</Metadata>
<Cryptograph>
<Key Id="client_secret" StorageReferenceId="key" />
</Cryptograph>
<IncludeTechnicalProfile ReferenceId="MIDC-Shared" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
<ClaimsProvider>
<Bomain> hey there 2</Bomain>
<Name>Login using </Name>
<TechnicalProfiles>
<TechnicalProfile Id="MIDC-What">
<DisplayName> Employee</DisplayName>
<Description>Login with your account</Description>
<Protocol Name="OpenIdConnect" />
<Metadata>
<Item Key="METADATA">https://login.microsoftonline.com</Item>
<Item Key="client_id">Mangal</Item>
<Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com</Item>
</Metadata>
<Cryptograph>
<Key Id="client_secret" StorageReferenceId="key" />
</Cryptograph>
<IncludeTechnicalProfile ReferenceId="MIDC-Shared" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
<ClaimsProvider>
<Bomain> hey there 3</Bomain>
<Name>Login using </Name>
<TechnicalProfiles>
<TechnicalProfile Id="MIDC-What">
<DisplayName> Employee</DisplayName>
<Description>Login with your account</Description>
<Protocol Name="OpenIdConnect" />
<Metadata>
<Item Key="METADATA">https://login.microsoftonline.com</Item>
<Item Key="client_id">Mangal</Item>
<Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com</Item>
</Metadata>
<Cryptograph>
<Key Id="client_secret" StorageReferenceId="key" />
</Cryptograph>
<IncludeTechnicalProfile ReferenceId="MIDC-Shared" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
</ClaimsProviders>
</TrustFrameworkPolicy>
I am doing this right now:
- Saving doc in a variable
$doc = [xml](Get-Content permissions.xml)
- Appending the child variable to $doc xml
[Void]$doc.TrustFrameworkPolicy.ClaimsProviders.AppendChild($childxml)
I am getting the following error:
Exception calling "AppendChild" with "1" argument(s): "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."