2

I have an xml tree as below

<Response>
<Terminal>
<Name>m1</Name>
<Value><Array1><DBL><Val>-0.143077</Val></DBL></Array1></Value>
</Terminal>
<Terminal>
<Name>m3</Name>
<Value><Array3><DBL><Val>-0.876611</Val></DBL></Array3></Value>
</Terminal>
<Terminal>
<Name>m2</Name>
<Value><Array2><DBL><Val>-0.459437</Val></DBL></Array2></Value>
</Terminal>
</Response>

I have to extract m1,m2,m3 values using action script

Can anyone help me in writing this code .

Is the below code is enough for this

for (var i=0; i<xml.Terminal.length(); i++) {

     if (xml.Terminal.Name.text()=="m1") {

                       voltage=xml.Terminal.Value.Array1.DBL.Val.text()
                              }
     else if (xml.Terminal[i].Name.text()=="m2") {

                      current=xml.Terminal.Value.Array2.DBL.Val.text();

                              }
     else if (xml.Terminal[i].Name.text()=="m3") {

                       temperature=xml.Terminal.Value.Array3.DBL.Val.text();

                            }
        }

        Menu_Content1.volt_val.text = voltage;
    Menu_Content1.curr_val.text = current;
    Menu_Content1.temp_val.text = temperature;
)

volt_val.text etc is for text display added in flash.

2 Answers 2

2

To parse a common formated tags in XML you have to first place them into a parent tage in your case create XML like this

<Response>
<**PARENT_TAG**>
<Terminal>
<Name>m1</Name>
<Value><Array1><DBL><Val>-0.143077</Val></DBL></Array1></Value>
</Terminal>
<Terminal>
<Name>m3</Name>
<Value><Array3><DBL><Val>-0.876611</Val></DBL></Array3></Value>
</Terminal>
<Terminal>
<Name>m2</Name>
<Value><Array2><DBL><Val>-0.459437</Val></DBL></Array2></Value>
</Terminal>
</**PARENT_TAG**>
</Response>

After that parsing of an XML in actionscript is very easy you just have to create an object of a XML and than use DOM format to get value of a particular tag As an example

var result:XML = new XML(event.target.data);

for(var i:int=0; i<result.PARENT_TAG.length; i++)
{
   trace(result.PARENT_TAG.Terminal[i].Name);

}
Sign up to request clarification or add additional context in comments.

Comments

1

yes,your idea is lead to right move.but you should first load xml file in object. You can use XML like here or here in your project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.