Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 我没有让AppendChild与PowerShell 2一起使用,但在版本3中它可以正常工作_Xml_Powershell_Powershell 2.0 - Fatal编程技术网

Xml 我没有让AppendChild与PowerShell 2一起使用,但在版本3中它可以正常工作

Xml 我没有让AppendChild与PowerShell 2一起使用,但在版本3中它可以正常工作,xml,powershell,powershell-2.0,Xml,Powershell,Powershell 2.0,我有一个XML-文件,我想在节点“Profile”内添加一个节点“Profile” 我收到以下错误消息: Method invocation failed because [System.Xml.XPathNodeList] doesn't contain a method named 'AppendChild'. At C:\Temp\Test\test.ps1:10 char:20 + $xmlElt.AppendChild <<<< ($xmlSubElt)

我有一个
XML
-文件,我想在节点“
Profile
”内添加一个节点“
Profile

我收到以下错误消息:

Method invocation failed because [System.Xml.XPathNodeList] doesn't contain a method named 'AppendChild'.
At C:\Temp\Test\test.ps1:10 char:20
+ $xmlElt.AppendChild <<<< ($xmlSubElt)
    + CategoryInfo          : InvalidOperation: (AppendChild:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
方法调用失败,因为[System.Xml.XPathNodeList]不包含名为“AppendChild”的方法。
在C:\Temp\Test\Test.ps1:10 char:20

+$xmlElt.AppendChild由于SelectNodes可以返回多个节点,因此需要在V2上迭代集合,例如,尝试:

$xmlElt | Foreach {$_.AppendChild($xmlSubElt)

或者,如果您只需要一个节点,请使用
选择singlenode()
。这在V3上有效,因为它将在调用属性或方法时自动枚举集合。

非常感谢。
Method invocation failed because [System.Xml.XPathNodeList] doesn't contain a method named 'AppendChild'.
At C:\Temp\Test\test.ps1:10 char:20
+ $xmlElt.AppendChild <<<< ($xmlSubElt)
    + CategoryInfo          : InvalidOperation: (AppendChild:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
$xmlElt | Foreach {$_.AppendChild($xmlSubElt)