Sharepoint XML in flash

Hi there,
Ive had an idea for a small application as a learning exercise. Its for a sharepoint 2007 website which my employer has.

It loads an xml file from the site’s webservice and retrieves all the data from a list.
If you look at the xml, attribue\value pairs they can be in any order from the webservice. Also depending on the list set up in sharepoint the column names in the list will be different and therefore the xml schema changes.
It sets up the namespaces
it the calls getRSAttribues (my shiney new piece of code :slight_smile:
It then creates a multidimensional array with the attribute names from the schema of the XML then queries the data with the dynamically set up attributes.

Its my first bit of action script and i would like some advice on how to improve the getRSAttribues function as the array seems to have an extra level to it. Any advice on how i would go about making it into a method or a parser/class/whatever would be very interesting.

Many thanks

Andy


var myXML:XML = new XML();
var XML_URL:String = "http://my.website.com/subsite/_vti_bin/owssvr.dll?Cmd=Display&List=%7BVE7E0G6A%2D0E8B%2D4773%2D8189%2D7F01126F8658%7D&XMLDATA=TRUE";
/* the address returns this xml:

<xml>
&#8722;
<s:Schema id="RowsetSchema">
&#8722;
<s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
&#8722;
<s:AttributeType name="ows_DocIcon" rs:name="Type" rs:number="1">
<s:datatype dt:type="string" dt:maxLength="512"/>
</s:AttributeType>
&#8722;
<s:AttributeType name="ows_URLwMenu" rs:name="URL" rs:number="2">
<s:datatype dt:type="string" dt:maxLength="512"/>
</s:AttributeType>
&#8722;
<s:AttributeType name="ows_Comments" rs:name="Notes" rs:number="3">
<s:datatype dt:type="string" dt:maxLength="1073741823"/>
</s:AttributeType>
&#8722;
<s:AttributeType name="ows_Disk" rs:name="Disk" rs:number="4">
<s:datatype dt:type="string" dt:maxLength="512"/>
</s:AttributeType>
</s:ElementType>
</s:Schema>
&#8722;
<rs:data>
<z:row ows_URLwMenu="URL1" ows_Disk="CD1"/>
<z:row ows_URLwMenu="URL2" ows_Disk="CD2" anoterAttribute="another value"/>
<z:row ows_URLwMenu="URL3" yetAnother="Set of Values" ows_Disk="CD3" />
</rs:data>
</xml>

*/


var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
var k:Number;
var arColumns:Array = new Array();
var arTemp:Array = new Array();
myLoader.addEventListener("complete", xmlLoaded);



function xmlLoaded(event:Event):void
{
    myXML = XML(myLoader.data);
    trace("Data loaded.");
// set namespaces    
var rsNS:Namespace = myXML.namespace("rs");
var zNS:Namespace = myXML.namespace("z");
var sNS:Namespace = myXML.namespace("s")
// create the arrays for the columns / attributes



// get the headings and column titles from the sNSAttributeType
var sAttributeType:XMLList = myXML.sNS::Schema.sNS::ElementType.sNS::AttributeType

getRSAttribues(sAttributeType, arColumns);

trace('arrays created, now tring to reference them.')

var rows:XMLList = myXML.rsNS::data;
var i:Number = 0;
var sRef:String;



for each (var zRow:XML in rows.zNS::row) {
    for (var col:Number = 0; col < arColumns.length; col++){
            sRef = "@" + arColumns[col][0][0];
            trace(arColumns[col][0][1] + " = " + zRow[sRef]);
    }
     i++;
}


}

function getRSAttribues(attributes_XML:XMLList, headings_ar:Array):void
{
    /* 
        first create an array to keep the info in then
        get the attribute elements from the XML like this:
        var sAttributeType:XMLList = myXML.sNS::Schema.sNS::ElementType.sNS::AttributeType
        
        then call funtion like this: getRSAttribues(sAttributeType, arColumns);
    */
    var arTemp:Array = new Array();
    
    for (var j:Number = 0; j < attributes_XML.length(); j++)
        {
            
            arTemp = new Array();
            
            for each (var attr:String in attributes_XML[j].attributes())
            {
                arTemp.push(attr);
            }
            headings_ar[j] = new Array();
            headings_ar[j].push(arTemp);
        }
        
trace('getRSAttributes(): got the attributes');
        
}