Accessing XML attributes Tip...

Accessing XML attributes Tip...

Hi Just a tip.....

If you ever need to drop a bunch of xml element attributes into a map variable. Here's how I did it. 

//create element variable

file = xml.executeXPath("/response/tree/folder/files/file");

//create a map to hold the attribute variables

data = map();

//make a list of attributes (note their is a way to do this agnostically where you don't know the name of the attribute
//prior. But it's more complicated..

attributes = {"id","created","shared","sha1","file_name","size","updated"};

//loop through you attribute list

for each r in attributes
      {
              //get the attribute node (this prints <attribute>value</attribute>
            node = file.executeXPath("/file/@"+r);

             //put the the attribute list instance as the key and then xpath the attribute to get the text value

            data.put(r,node.executeXPath("/"+r+"/text()"));
      }
//save this data map AS A STRING (DID YOU KNOW YOU CAN DO THIS AND THEN USE toMap() to get it back into a map?)

responseMap.put("message",data.toString());

-Stephen Rhyne
Owner
Rhyne Design
@srhyne