获取xml body的所有元素并添加到struct [英] get all elements of xml body and add to struct
问题描述
我正在寻找一种方法来循环遍历XML体,并将每个xml元素传递到一个结构体。
我以这种方式访问xml主体:
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:
<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#" />
所以我可以得到args的每个元素,如果它不是一个complexType。要访问复杂元素的子元素,我使用这种方式:
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:
<cfset var children = "" />
<cfset children = args[3].xmlchildren />
<cfset children = args[1].xmlchildren />
第三个元素的XML如下所示:
XML for the third element looks like this:
<Element>
<item>
<child1>XP_RA_10</child1>
<child2>RA-EXPRESS-KATALOG</Wmvtx>
</item>
</Element>
但我想创建一个方法来检查是否有任何xmlchildren。
我试图这样做...
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...
<cfif ArrayIsDefined(i.xmlchildren, 1)>
<cfset children = args[i].xmlchildren />
<cfif ArrayIsDefined(children[1].xmlchildren, 1)>
<!--- if more xmlchildren exist --->
<cfelse>
<!if one xmlchildren exist --->
</cfif>
<cfelse>
<!--- if xmlchidren doesn't exist --->
</cfif>
...但我不能访问元素,贝沃。总是得到结构体未定义的错误....
...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?
推荐答案
这是您要找的吗? RIAForge上的XmlToStruct
这篇关于获取xml body的所有元素并添加到struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!