A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: I need help speeding up parsing

  1. #1
    Junior Member
    Join Date
    Nov 2001
    Posts
    2

    I need help speeding up parsing

    I need help improving the speed of my XML parsing and display of information.

    I need to display hierarchical data generated from a live datasource. I wasn't satisfied with the look and feel I got using HTML so I turned to Flash and XML.

    Right now it takes the parser about 10 secs to load and parse the data regardless of the size of the XML. Any suggestions as to how I might improve performance would be greatly appreciated

    Below is a brief summary and links to the movie and data

    Thanks in advance for any help!
    -H


    Here is the Flash movie
    http://www.arts.uci.edu/jvaldry/jv2/remote.html

    Here is the XML
    http://www.arts.uci.edu/jvaldry/jv2/writexml.asp


    I need the display to be dynamic so I decided to loop thru the xml and dynamically create an array of variables in flash that appends the xml elements

    if the xml reads

    <P>&lt;tabledef&gt;</P>
    <P> &lt;column&gt;one&lt;/column&gt;</P>
    <P> &lt;column&gt;two&lt;/column&gt;</P>
    <P> &lt;column&gt;three&lt;/column&gt;</P>
    <P>&lt;/tabledef&gt;</P>
    <P>&lt;tabledata&gt;</P>
    <P> &lt;data&gt;A&lt;/data&gt;</P>
    <P> &lt;data&gt;B&lt;/data&gt;</P>
    <P> &lt;data&gt;C&lt;/data&gt;</P>
    <P> &lt;data&gt;D&lt;/data&gt;</P>
    <P> &lt;data&gt;E&lt;/data&gt;</P>
    <P> &lt;data&gt;F&lt;/data&gt;</P>
    <P>&lt;/tabledata&gt;</P>

    The flash script creates three variables for the three columns and then appends the data tags to their respective columns. so the variables will looks like this

    array[0]:AD
    array[1]:BE
    array[2]:CF

    ------------------------------------------------
    Here is the Script I run to parse the data
    ------------------------------------------------

    urlXML = new XML();
    arrRecordData= new array();
    arrRecordIDs= new array();

    intLeftVisibleColumn=3;


    urlXML.onLoad = convertXML;

    urlXML.load("http://www.arts.uci.edu/jvaldry/jv2/writexml.asp");


    InitializeRecords();


    SwitchButtons(1);

    stop ();



    function convertXML() {
    mainTag = new XML;
    elementTag = new XML;
    TableElements = new Array;
    DefList = new Array;
    elementList = new Array;
    strAppend = "";
    strFormat = "";
    strNodeType="";

    colname=0;
    i=0;
    j=0;
    k=0;
    m=0;
    n=0;

    total_cols=12;

    //first get a handle on the first actual element in the document.
    //note we skip to the nextSibling element, since the first element
    //is a document definition tag.

    mainTag = this.firstChild.nextSibling;

    //make sure we have the right parent tag. Do this by looking at the nodeName property
    //for this object. This will correspond exactly to the <nodeName>, where nodeName is replaced
    //with the name of your xml tag

    if(mainTag.nodeName.toLowerCase() == "contractsdiscussion") {

    //if we have a match, create variables for the columns
    TableElements = mainTag.childNodes;
    //now we loop over all the elemetnts, tabledefs and table data...

    for(i=0;i<=TableElements.length;i++){
    //initialize variables to hold xml data we want displayed
    if(TableElements[i].nodeName.toLowerCase() == "tabledef") {
    //we get the child node array element
    DefList = TableElements[i].childNodes;
    //and loop through that looking for the data we need

    for(j=0;j<=DefList.length;j++) {

    }
    }else{


    //table data


    elementList = TableElements[i].childNodes;

    //and loop through that looking for the data we need

    for(k=0;k<=elementList.length;k++){

    elementtag=elementlist[k];
    strNodeType=elementtag.nodename.tolowercase()

    if(strNodeType=="data"){
    if (strformat <> "") {

    strAppend = "<p>" + "<" + strFormat + ">" + elementtag.firstchild.nodeValue +"</" + strformat + ">" + "</p>";
    strFormat = "";

    } else {
    strAppend = "<p>" + elementtag.firstchild.nodeValue +"</p>";
    }

    arrRecordData[colname] = arrRecordData[colname] + strAppend;
    strAppend="";

    if (colname>=total_cols){
    colname=0;
    }else{
    colname=colname+1;
    }

    } else if(strNodeType=="format"){
    strFormat = elementtag.firstchild.nodeValue

    } else if(strNodeType=="skip"){
    for(m=0;m<=total_cols;m++){
    arrRecordData[m] = arrRecordData[m] + "<p></p>";
    }
    } else if(strNodeType=="font"){
    for(n=0;n<=total_cols;n++){
    arrRecordData[n] = arrRecordData[n] + "<" + elementtag.firstchild.nodeValue + ">";
    }
    }else if(strNodeType=="relid"){
    arrRecordIDs.push( elementtag.firstchild.nodeValue )
    }

    }
    }

    }


    PlaceData(intLeftVisibleColumn);

    delete(urlxml);


    }
    }



    function PlaceData(intArrayColumn) {


    intCurrentArray=intArrayColumn;
    strArrayContent="";

    visible_col_1 = arrRecordData[0];
    visible_col_2 = arrRecordData[1];
    visible_col_3 = arrRecordData[2];

    for (i=4; i<=8; i++ ) {
    if (intcurrentarray<= arrRecordData.length-1) {
    strArrayContent=arrRecordData[intcurrentarray]
    }else{ strArrayContent = ""
    }

    eval("visible_col_" + i)=strArrayContent

    intCurrentArray=intCurrentArray+1
    }
    }







  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Uhh...

    Before I trudge through all of your code...

    You don't need new XML objects to store node data, if you'r only grabbing info from them, and discarding them.

    In the end I bet you've made this a lot harder than it needs to be.

    If your XML looks like this:

    < tabledef>
    < column > one < / column >
    < column > two < / column >
    < column > three < / column >
    < / tabledef >
    < tabledata >
    < data > A < / data >
    < data > B < / data >
    < data > C < / data >
    < data > D < / data >
    < data > E < / data >
    < data > F < / data >
    < / tabledata >

    I'd redo it. I'd write it much shorter. Like this:

    < tableDef column="3" data="A|B|C|D|E|F" />

    That is a much nicer way - for human eyes, and for Flashs built in parser. (personally I think its light-years more efficient as well... )

    Then your code only has to look like this:

    myXML = new XML;
    myXML.onLoad = handleLoad;
    myXML.load("whateverURL/yourScript.asp");

    function handleLoad(status){
    status ? parseXML(myXML.childNodes[0]) : trace("XML error: "+myXML.status);
    }

    function parseXML(currentNode){
    // Are we at the right node??
    if(currentNode.nodeName=="tableDef"){
    // How many columns do we need?
    totalColumns = currentNode.attributes['column'];
    // Let's take our data and put it in an array
    dataArray = currentNode.attributes['data'].split("|");
    // Let's figure out data per column
    dataMultiplier = dataArray.length / totalColumns;
    // Let's loop through each column
    for(var i = 0; i < totalColumns; i++){
    // Let's loop through the number of data we need in each column
    for(var j = 0; j < dataMultiplier; j+=totalColumns){
    // Let's grab from the correct position in our data array
    // Then let's add it all together
    // spacing added on the 'i' to avoide italics...
    holdArray [ i ] += dataArray[j];
    }
    }
    }


    I haven't actually tried out that code, but the concept is good... you can trace your array to see if it's right.

    P.s. - That was kinda fun!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center