ColdFusion - how to loop through XML output and adding to struct or array?

后端 未结 2 1252
梦如初夏
梦如初夏 2021-01-25 14:03

I am trying to create a list of Chapter Officers and their respective positions. The data comes from a series of XML key/value pairs accessed via web service (Key: Member_Name,

2条回答
  •  被撕碎了的回忆
    2021-01-25 14:33

    Here's how I would probably solve this:

    
    
    
    
    
        
            
            
        
            
        
    
    
    

    It uses the existing XmlSearch you've done, and assumes Member_Guid is always the first key/value pair. I've used var/local scope assuming this is going inside a function (which it probably should be), but if not just remove them.

    It uses structs so lookup of a particular GUID is easy, but order isn't preserved (though if necessary you could keep a separate array to do that), and you don't have to remember which array position matches to which key.

    If you wanted to lookup based on other fields, you could also convert the data into a query, like so:

    
    
    
    
    
        
            
        
    
        
    
    
    

    This maintains order and makes more general lookup easier, also makes it easier if your main use is outputting direct to HTML.

    I've hard-coded the column keys there, but you could also do a pre-loop to collate those first, if they are something that is liable to change.


    Hopefully this all makes sense?

提交回复
热议问题