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)