I keep running into this error message when I tray to pass and xml to a function:
Cannot process argument transformation on parameter
‘XmlDocument’. Cannot convert value “System.Object” to type “System.Xml.XmlDocument”. Error:
“The specified node cannot be inserted as the valid child of this node, because the specified
node is the wrong type.”
#I have tried many different declarations:
#Option 1
$XmlDocument=New-Object System.XML.XMLDocument
$XmlDocument.Load("C:\Users\xml.xml")
#Option 2
$XmlDocument = (Get-Content -Path "C:\Users\xml.xml")
#Forcing the object being passed to xml:
$Test = Get-XmlNamespaceManager([ xml ]$XmlDocument)
$Test = Get-XmlNamespaceManager([system.xml.xmlelement]$XmlDocument)
#Forcing the object being received to xml:
function Get-XmlNamespaceManager([ xml ]$XmlDocument){}
function Get-XmlNamespaceManager2([system.xml.xmlelement]$XmlDocument){}
The only way I have got it to work is if I just pass the string of the file name and run the .Load, .LoadXml, or Get-Content in the function.
I really want to understand how to pass the xml object to a function without PowerShell throwing an error.
OK I have put on my dunce cap and am anxiously awaiting lessons from all the PowerShell masters out there.
Thanks in advance.