dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Simple XML array node target problem... Newbie

  1. #1
    Junior Member
    Join Date
    Dec 2000
    Posts
    7

    Simple XML array node target problem... Newbie

    I am having a problem selecting only the first node value from this xml tree "xx" no matter how many dev items returned from array 2 or 200. I have been able to select the first item but I get hung up writing an array. New to actionsript learning is school, I spent time searching the board, if this is posted elsewhere please refer.

    This is the target to find all first nodes only from an array that I am using. I know it is incorrect.
    ArrValue[i] = BaseNode.FirstNode.childNodes[i]


    Thanks for any guidance.




    Code:
    <?xml version="1.0"  encoding="ISO-8859-1"?>
    <data>
    <dev label="Sep 03" >
            <xx>76084.71</xx>
            <ww>52946.77</ww>
            <ee>64058.4</ee>
    </dev>
    <dev label="Sep 04" >
            <xx>117638.69</xx>
            <ww>72082.64</ww>
            <ee>94867.35</ee>
    </dev>
    </data
    
    
    ACTIONSCRIPT-----------------------
    
    
    function LoadSchoolData() {
       var BaseNode = thisXML.childNodes[0];
       
       
       //set up arrays
       var ArrLabel = new Array();
       var ArrValue = new Array();	
       var ThisNode;
       
       
       //create datasource
       var SchoolData = new DataProviderClass();
       
       
       //get Data
       for (var i=0; i >< BaseNode.childNodes.length; i++) {
          ThisNode = BaseNode.childNodes[i];
          ArrLabel[i] = ThisNode.attributes["label"];
          
         /* I am having a problem with the ArrValue[i] selecting all the "<xx>76084.71</xx>"  node from the tree from an array  no matter if it is 1 or 100.*/
          
          ArrValue[i] = BaseNode.FirstNode.childNodes[i];
          SchoolData.addItem({CW:ArrLabel[i], TB:ArrValue[i]});
       }
       MyDev.setDataProvider(SchoolData);
       MyDev.setLabelSource("CW");
       MyDev.setValueSource("TB");
    }
    Last edited by revenekorb; 03-02-2008 at 12:50 PM.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    set up a 2D array to hold the dev items
    PHP Code:
    function LoadSchoolData() {
       var 
    BaseNode thisXML.childNodes[0];
       var 
    ArrLabel = new Array();
       var 
    ArrValue = new Array();    
       var 
    ThisNode;

       for (var 
    i=0i<BaseNode.childNodes.lengthi++) {
        
    ThisNode BaseNode.childNodes[i]; 
        
    len2 ThisNode.childNodes.length
        
    ArrLabel[i] = ThisNode.attributes["label"];
        
    ArrValue[i] = new Array();
        for (var 
    ii=0ii<len2ii++) {
        
    ArrValue[i][ii] = ThisNode.childNodes[ii].firstChild;
        
    trace("ArrValue["+i+"]["+ii+"] "+ArrValue[i][ii])
        }
        }
    }; 
    hth

  3. #3
    Junior Member
    Join Date
    Dec 2000
    Posts
    7
    I will continue to explore so one day I can give back to the board.

    Thanks. This works well.

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you're welcome

    Good Hunting

  5. #5
    Junior Member
    Join Date
    Dec 2000
    Posts
    7
    I thought I had this school project solved, but when I examined the output, it seems that I must

    be still doing something wrong. It still picks up unwanted data/nodes. I only need the first node <eb> values to plot not any of the other values. The xml tree cannot change. Any help would be appreciated.

    XML and actionscript below.



    You can download the source here.



    www.i-codedesign.com/ct2.fla

    www.i-codedesign.com/zload.xml




    XML TREE Data--- Need only the label attribute and the <eb></eb> value only. To plot on the

    chart. The XML Tree cannot change.





    <?xml version="1.0" encoding="UTF-8"?>

    <data>

    <Chart label="Jan 00">

    <eb>1000</eb>

    <ec>1200</ec>

    <ee>1290</ee>

    <ci>1500</ci>

    </Chart>

    <Chart label="Jan 01">

    <eb>900</eb>

    <ec>1200</ec>

    <ee>1290</ee>

    <ci>1500</ci>

    </Chart>

    </data>



    Actionscript-------- Problem finding the correct code for selecting the first Node.



    function LoadChartData() {

    var BaseNode = thisXML.childNodes[0];
    var ArrLabel = new Array();
    var ArrValue = new Array();
    var ThisNode;

    var ChartData = new DataProviderClass();

    for (var i=0; i<BaseNode.childNodes.length; i++) {
    ThisNode = BaseNode.childNodes[i];
    len2 = ThisNode.childNodes.length;
    ArrLabel[i] = ThisNode.attributes["label"];
    ArrValue[i] = new Array();
    for (var ii=0; ii<len2; ii++) {
    ArrValue[i][ii] = ThisNode.childNodes[ii].firstChild;
    trace("ArrValue["+i+"]["+ii+"] "+ArrValue[i][ii]);
    trace(ArrLabel[i]);

    trace(len2);

    ChartData.addItem({CW:ArrLabel[ii], TB:ArrValue[ii]});
    }

    MyChart.setDataProvider(ChartData);
    MyChart.setLabelSource("CW");
    MyChart.setValueSource("TB");

    //get Chart Title
    var ChartTitle;
    if (BaseNode.attributes["ThisTitle"].length > 0) {
    ChartTitle = BaseNode.attributes["label"];
    }
    else {
    ChartTitle = " ";
    }
    MyChart.setChartTitle(ChartTitle);
    }
    }

  6. #6
    Junior Member
    Join Date
    Dec 2000
    Posts
    7
    I thought I had this school project solved, but when I examined the output, it seems that I must

    be still doing something wrong. It still picks up unwanted data/nodes. I only need the first node <eb> values to plot not any of the other values. The xml tree cannot change. Any help would be appreciated.

    XML and actionscript below.



    You can download the source here.



    www.i-codedesign.com/ct2.fla

    www.i-codedesign.com/zload.xml




    XML TREE Data--- Need only the label attribute and the <eb></eb> value only. To plot on the

    chart. The XML Tree cannot change.





    <?xml version="1.0" encoding="UTF-8"?>

    <data>

    <Chart label="Jan 00">

    <eb>1000</eb>

    <ec>1200</ec>

    <ee>1290</ee>

    <ci>1500</ci>

    </Chart>

    <Chart label="Jan 01">

    <eb>900</eb>

    <ec>1200</ec>

    <ee>1290</ee>

    <ci>1500</ci>

    </Chart>

    </data>



    Actionscript-------- Problem finding the correct code for selecting the first Node.



    function LoadChartData() {

    var BaseNode = thisXML.childNodes[0];
    var ArrLabel = new Array();
    var ArrValue = new Array();
    var ThisNode;

    var ChartData = new DataProviderClass();

    for (var i=0; i<BaseNode.childNodes.length; i++) {
    ThisNode = BaseNode.childNodes[i];
    len2 = ThisNode.childNodes.length;
    ArrLabel[i] = ThisNode.attributes["label"];
    ArrValue[i] = new Array();
    for (var ii=0; ii<len2; ii++) {
    ArrValue[i][ii] = ThisNode.childNodes[ii].firstChild;
    trace("ArrValue["+i+"]["+ii+"] "+ArrValue[i][ii]);
    trace(ArrLabel[i]);

    trace(len2);

    ChartData.addItem({CW:ArrLabel[ii], TB:ArrValue[ii]});
    }

    MyChart.setDataProvider(ChartData);
    MyChart.setLabelSource("CW");
    MyChart.setValueSource("TB");

    //get Chart Title
    var ChartTitle;
    if (BaseNode.attributes["ThisTitle"].length > 0) {
    ChartTitle = BaseNode.attributes["label"];
    }
    else {
    ChartTitle = " ";
    }
    MyChart.setChartTitle(ChartTitle);
    }
    }

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    cannot open Flash 9 files here

    can you use removeTreeNodeAt(index)
    or the Flash 9 equivalent code ?

  8. #8
    Junior Member
    Join Date
    Dec 2000
    Posts
    7
    a_modified_dog thanks for your help again. I finally solved my issue.

    I targeted my node using this path.

    ArrValue[i] = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;

    Now I am able to select the first node only.

    I do appreciate your reply.

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