Getting key from structure

monobrau's picture

Hi all,

I'm looking for a way to read the key string from a structure (see enclosed pic).

Know any method?

PreviewAttachmentSize
structurem.jpg
structurem.jpg79.56 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

usefuldesign.au's picture
Re: Getting key from structure

This is the way I know.

function (__string Out) main (__structure StructIn)
{
   var result = new Object();
   var msg = new String;
   msg = "" ;
   if (StructIn)
   {
      k=1
      for (i in StructIn[0])
      {
         if (k%3==0) CR=String.fromCharCode(13) 
            else CR=""
         msg = msg + i + "   " + CR;
         k++
      }
   }
   result.Out = msg;
   return result;
}
PreviewAttachmentSize
What key is that in?.qtz13.48 KB

monobrau's picture
Re: Getting key from structure

Just modified it a bit to give me the top level key's

function (__string Out) main (__structure StructIn)
{
    var result = new Object();
    var msg = new String;
    msg = "" ;
    if (StructIn)
    {
        k=1
        for (i in StructIn)
        {
            if (k%3==0) CR=String.fromCharCode(32) 
                else CR=""
            msg = msg + i + "   " + CR;
            k++
        }
    }
    result.Out = msg;
    return result;
}

And it works like a charm, just what I needed.

Thanks!

usefuldesign.au's picture
Re: Getting key from structure

No worries.

Yes, that was tailored to work for the xml file the XML Downloader patch defaults to: http://www.apple.com/main/rss/hotnews/hotnews.rss

As per comp in my other post (for future reference).

itsthejayj's picture
Re: Getting key from structure

I've stop using this javascript method for Smokris 'structure ket at index' patch http://kineme.net/composition/smokris/StructureKeyIndex ;- i think subconsciously i trust smokris workings more than my own!

usefuldesign.au's picture
Structure Key from Nested Indexes

You may not trust my JS since I'm a new convert ;-). This is my super Structure Key at Index patch – an extension of smokris's patch. It will dig down to 3 levels to get the key, or 2 levels if you leave Index_2 input blank (not zero, blank = ""). Extensible as far down as you want.

itsthejayj's picture
Re: Structure Key from Nested Indexes

@ usefuldesign.au I like and i trust your JS :) (no offense meant before it was more of a reflection on my own ability when it comes to javascript!). Its a VERY useful patch indeed. Something like this should be a stock patch.