I m running into an issues appending an xml attribute fragment. I had this working but now im getting the below errors. Below is the default xml structure and I want to add items under the Assignments node.
<?xml version="1.0"?><Database><Info><Name>FinalTest</Name><TotalComputers>759</TotalComputers><Assigned>0</Assigned><Unassigned>759</Unassigned></Info><Assignments/></Database>
My Code:
[XML]$xml = Get-Content "C:\Users\shuppz\Desktop\FinalTest.xml"
$txt = @"<Assignment><File>First_Last.xlsx</File><Computers>Computer1, Computer2, Computer3</Computers><Assigned>12/12/1212</Assigned><Due>12/21/1212</Due></Assignment>"@
$xmlFragment=$xml.CreateDocumentFragment($txt)
$node=$xml.SelectSingleNode('//Assignments')
$node.AppendChild($xmlFragment)The Errors:
Cannot find an overload for "CreateDocumentFragment" and the argument count: "1". At line:12 char:1+ $xmlFragment=$xml.CreateDocumentFragment($txt)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodException+ FullyQualifiedErrorId : MethodCountCouldNotFindBest Exception calling "AppendChild" with "1" argument(s): "Object reference not set to an instance of an object." At line:14 char:1+ $node.AppendChild($xmlFragment)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : DotNetMethodException
If I do $XML | GM I see that CreateDocumentFragment, if someone could show me what im doing wrong. Im sure im missing something simple.