WasStaX GetNodeValue

From Second Life Wiki
Jump to navigation Jump to search

GetNodeValue

This function traverses a flat XML file, passes as the parameter xmlStream and returns the data contained in the node, node.

For further details, please see Wizardry and Steamworks/StaX.

<lsl> ////////////////////////////////////////////////////////// // [K] Kira Komarov - 2011, License: GPLv3 // //////////////////////////////////////////////////////////

string wasStaX_GetNodeValue(string xmlStream, string node) {

   list stream = llParseString2List(xmlStream, [" "], ["<", ">", "/"]);
   integer size = llGetListLength(stream);
   list StaX = [];
   string value = "";
   integer ptr = 0;
   do {
       string current = llList2String(stream, ptr);
       string lookback = llList2String(stream, ptr-1);
       if(current != "/" && lookback == "<") {
           StaX += current;
           jump next_tag;
       }
       if(lookback == "/") {
           StaX = llDeleteSubList(StaX, llGetListLength(StaX)-1, llGetListLength(StaX)-1);
           jump next_tag;
       }
       if(current != ">" && current != "/" && current != "<") 
           if(llList2String(StaX,llGetListLength(StaX)-1) == node)
               value += current + " ";  

@next_tag;

   } while(++ptr<size);
   
   if(llGetListLength(StaX) != 0) {
       llSay(DEBUG_CHANNEL, "The following tags may be unmatched: " + llDumpList2String(StaX, ",") + ". Please check your file.");
   }
   return value;

} </lsl>