![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | XML node passed to function I'm working on a script that converts a specific format of XML file to a CSV document. I'm getting stuck at a point where I pass an object of type System.Xml.XmlElement to a function, but the function receives an object of type System.Object[] instead. I've confirmed with debugging that these types are, in fact, what are being passed and received. I can't figure out why the variable gets changed to System.Object[] by the time it gets into the function. I've tried building other XML-parsing scripts that only deal with passing XML variables to functions, and these scripts work correctly. They do not change the object type before it enters the function. Can someone look at this script and tell me why the GetHeaders function thinks it's getting a $XMLnode variable of type System.Object[] instead of System.Xml.XmlElement? param ($InputXML = (throw "You must specify an input XML file.")) function GetHeaders ($XMLnode, $RecordType) { if ($XMLnode -is "System.Xml.XmlText") { Add-Content -Path $RecordType + "s.csv" -Value $XMLnode.get_Name() } else { foreach ($ChildNode in $XMLnode.get_ChildNodes()) { GetHeaders($ChildNode, $RecordType) } } } function GetData ($XMLnode, $RecordType) { if ($XMLnode -is "System.Xml.XmlText") { Add-Content -Path $RecordType + "s.csv" -Value $XMLnode.get_InnerText() } else { foreach ($ChildNode in $XMLnode.get_ChildNodes()) { GetHeaders($ChildNode, $RecordType) } } } [xml] $xml = Get-Content -Path $InputXML $RequisitionCandidates = $xml.VisionDataExchange.ExportData.get_ChildNodes() foreach ($RequisitionCandidate in $RequisitionCandidates) { GetHeaders($RequisitionCandidate.Candidate, "Candidate") Add-Content -Path Candidates.csv -Value "`n" GetData($RequisitionCandidate.Candidate, "Candidate") Add-Content -Path Candidates.csv -Value "`n" GetHeaders($RequisitionCandidate.Requisition, "Requisition") Add-Content -Path Requisitions.csv -Value "`n" GetData($RequisitionCandidate.Requisition, "Requisition") Add-Content -Path Requisitions.csv -Value "`n" } -- David Stardate 8525.2 |
| | #2 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: XML node passed to function On Jul 10, 4:21*pm, David Trimboli <trimb...@xxxxxx> wrote:
This is a common source of confusion in powershell. .NET methods use brackets and comma separated arguments, but powershell functions do not. Case in point:
As you can see, $a is object[] with two elements: 1 & 2. So, in short you should space separate your function arguments. - Oisin PowerShell MVP http://www.nivot.org/ | ||||||||||||||||||||||||||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: XML node passed to function Oisin (x0n) Grehan [MVP] wrote:
Thanks, Oisin. -- David Stardate 8527.1 | ||||||||||||||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: XML node passed to function Hehe, this still happens to me even today Having IDE that will havespecial highlight whenever you use () with functions would save me lot of time ![]() Martin "David Trimboli" <trimboli@xxxxxx> wrote in message news:ea9mmi14IHA.4272@xxxxxx
| ||||||||||||||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: XML node passed to function Martin Zugec wrote:
that I treat them the same way... -- David Stardate 8538.2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shouldn't this give me the active node on the cluster? | akcorr | PowerShell | 1 | 05-19-2008 12:47 PM |
| Removing an XML node | Leon Mayne | .NET General | 1 | 02-27-2008 10:04 AM |
| How to delete a DFS node using Powershell | Richard Adams | PowerShell | 1 | 02-19-2008 08:03 PM |
| How many parameters ($args) can be passed to a function? | Kryten | PowerShell | 7 | 11-06-2007 11:56 PM |
| Counting a particular node in a XML file | Nikhil R. Bhandari | PowerShell | 0 | 04-03-2007 03:06 AM |