get all elements of xml body and add to struct

前端 未结 2 1645
情深已故
情深已故 2021-01-26 09:09

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:



        
相关标签:
2条回答
  • 2021-01-26 09:46

    unless you know the structure of the XML object ahead of time you will have to test each child object and traverse down the nodes till you know you have a simple object. To help there are the "is" functions as in:

    isObject(var);
    isStruct(var);
    isArray(var);
    isSimpleValue(variable);
    

    Once you know you have an array (for example) you loop through it's index by length as in:

    <Cfif isArray(children)>
    <cfloop form="1" to="#arraylen(children)#" index="i">
          <cfset thisNode = children[i]/>
          <cfif isStruct(thisNode)?
             .... do something with the structkeylist.
          </cfif>
         <Cfif isArray(thisNode)>
            .... more looping...
         </cfif>
    </cfloop>
    </cfif>
    

    This can be pretty daunting for really complex objects. I'm curious as to why you would do it? XML is designed to be "non-flat" - is there a specific requirement to flatten it?

    0 讨论(0)
  • 2021-01-26 09:46

    Is this what you were looking for? XmlToStruct on RIAForge

    0 讨论(0)
提交回复
热议问题