0

I would like to parse the following xml flow :

<telhdl:leg>
  <tel:deviceId>82085625</tel:deviceId>
  <tel:media>AUDIO</tel:media>
  <tel:state>ACTIVE</tel:state>
  <tel:capabilities>
    <tel:drop>true</tel:drop>
    <tel:hold>true</tel:hold>
    <tel:mute>true</tel:mute>
    <tel:sendDtmf>true</tel:sendDtmf>
  </tel:capabilities>
</telhdl:leg>
<telhdl:leg>
  <tel:deviceId>82085625</tel:deviceId>
  <tel:media>VIDEO</tel:media>
  <tel:state>ACTIVE</tel:state>
  <tel:muted>true</tel:muted>-
  <tel:capabilities>
    <tel:drop>true</tel:drop>
    <tel:unMute>true</tel:unMute>
  </tel:capabilities>
</telhdl:leg>

As you can see, there is 2 groups of leg, but in one of them there is an attributes which is not present in the other (muted) for example.

I have tried to parse it using this code :

$(xmlDoc).find('telhdl\\\\:deviceId,deviceId'); with $(xmlDoc) is the document node.

It works fine, but i don't know how to parse correctly this file to have as result an array which contain information of the 2 legs block.

The question is more : How to have clerary a result of the parsing ?

1
  • You will have to build the array yourself with $(xmlDoc).each(....) Commented Aug 13, 2013 at 14:44

1 Answer 1

2

This should do the trick:

$(xmlDoc).find("telhdl").each(function() {
    var deviceId = $(this).find("deviceId").text();
    var media = $(this).find("media").text();
    ....etc....
    var array = new Array(deviceId,media,...etc...);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it was the solution. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.