get all elements of xml body and add to struct

前端 未结 2 1685
情深已故
情深已故 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:

    
    
          
          
         
            .... more looping...
         
    
    
    

    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?

提交回复
热议问题