Powershell 将Xml字符串添加到Xml节点

Powershell 将Xml字符串添加到Xml节点,powershell,Powershell,我已经在谷歌上搜索了一段时间了,我要退出了 所以我有一个XML字符串: $xmlPom = [xml]"<repositories> <repository> <id>Test-Org</id> <url>https://pkgs.dev.azure.com/Test/_packaging/Test-Org/maven/v1</url> <releases> <enabled>tru

我已经在谷歌上搜索了一段时间了,我要退出了

所以我有一个XML字符串:

$xmlPom = [xml]"<repositories>
<repository>
<id>Test-Org</id>
<url>https://pkgs.dev.azure.com/Test/_packaging/Test-Org/maven/v1</url>
<releases>
    <enabled>true</enabled>
</releases>
<snapshots>
    <enabled>true</enabled>
</snapshots>
</repository>
</repositories>"
当我运行此操作时,会出现以下错误:

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."
At line:47 char:1
+ $xdoc.project.AppendChild($xmlPom)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

有什么想法吗?

就在我按下提交按钮时,我想到了

我只需要导入节点:

$xdoc.project.AppendChild($xdoc.ImportNode($xmlPom.repositories, $true))
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."
At line:47 char:1
+ $xdoc.project.AppendChild($xmlPom)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
$xdoc.project.AppendChild($xdoc.ImportNode($xmlPom.repositories, $true))