1

I used HTTPService for reading xml, but I want only a particular xml field value like the first node id.

The HTTPService object is:

<mx:HTTPService result="getid(event)" id="xml_coupon" url="###" useProxy="false" resultFormat="e4x"/>

The getid(event) function is:

public function getid(evt:ResultEvent):void
{
    var id:number=evt.result.id;
    Alert.show(id.tostring);
}

The getid function shows all ids, but I want the first index id only. How can I read this? I tried Alert.show(evt.getChildAt(1).id); but it shows an error. If you know, please help me.

1

1 Answer 1

3

hey do some thing like this

if xml is like this

<mx:XML id="usersXML">
  <root>
    <users>
      <user id="1" lovesDonuts="Yes">
        <firstname>Tariq</firstname>
        <lastname>Ahmed</lastname>
      </user>
      <user id="2" lovesDonuts="Yes">
        <firstname>Jon</firstname>
        <lastname>Hirschi</lastname>
      </user>
    </users>
  </root>
</mx:XML>

then do this

usersXML.users.user[1].firstname

for id

usersXML.users.user[1].@id
Sign up to request clarification or add additional context in comments.

2 Comments

This is the right idea, but so there is no confusion, you are returning "Jon" and "2", not "Tariq" and "1". The first user is the [0] index.
hey welcome you recommend you to go through chapter 15 of Flex 3 in action for more tricks of E4X

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.