get all elements of xml body and add to struct

rana1

New Member
I am looking for a way to loop through an XML-Body and pass each xml element into a struct.i got access to the xml body in this way:\[code\]<cfset var x = arguments.httpRequest /><cfset cont = xmlparse(x) /><cfset var body = xmlsearch(cont, "//SOAP-ENV:Body")[1] /><cfset var args = body.xmlchildren[1].xmlchildren /><cfset xmlElements = {} /><cfset xmlElements["#args[1].xmlName#"] = "#args[1].xmlText#" />\[/code\]so i can get each element of args if it isn't a complexType. To access the children of the complex elements i used this way:\[code\]<cfset var children = "" /><cfset children = args[3].xmlchildren /><cfset children = args[1].xmlchildren />\[/code\]XML for the third element looks like this:\[code\]<Element> <item> <child1>XP_RA_10</child1> <child2>RA-EXPRESS-KATALOG</Wmvtx> </item></Element>\[/code\]But i would like to create a method which does check if there are any xmlchildren or not.I tried to do it that way...\[code\]<cfif ArrayIsDefined(i.xmlchildren, 1)> <cfset children = args.xmlchildren /> <cfif ArrayIsDefined(children[1].xmlchildren, 1)> <!--- if more xmlchildren exist ---> <cfelse> <!if one xmlchildren exist ---> </cfif><cfelse> <!--- if xmlchidren doesn't exist ---></cfif>\[/code\]...but i don't get access to the elements to insert them into the struct i created bevor. Always getting an error that the struct is undefined....Is it the right way to check if there are any child-elements?
 
Back
Top