【发布时间】:2021-04-22 10:29:03
【问题描述】:
从我试图将 XML 节点附加到父 XML 元素的一周开始,我就一直坚持这一点。子节点和父节点如下所示:
[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>
"@
我想把这个子节点添加到这个文件中(文件名: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>
我现在正在这样做:
- 在变量中保存文档
$doc = [xml](Get-Content permissions.xml)
- 将子变量附加到 $doc xml
[Void]$doc.TrustFrameworkPolicy.ClaimsProviders.AppendChild($childxml)
我收到以下错误:
使用“1”参数调用“AppendChild”的异常:“指定的节点不能作为该节点的有效子节点插入,因为指定的节点类型错误。”
【问题讨论】:
-
为什么说powershell 5是你正在使用的版本……然后为v2、v3和v4添加标签?
-
@Lee_Dailey 抱歉改了。
-
谢谢!我很困惑...... [咧嘴笑]
标签: xml powershell azure-devops azure-powershell powershell-5.0