AllisonC
AllisonC

Reputation: 3099

How do I get the value of this xml?

I have the following xml:

<Order>
  <size width="16.5" height="19.5">
    <width>16.5</width>
    <height>19.5</height>
  </size>
  ...
</Order>

I have tried the following to get the value of width/height:

width = parseFloat(doc.getElementsByTagName('width')[0].innerHTML);
height = parseFloat(doc.getElementsByTagName('height')[0].innerHTML);

However in the default Android browser and IE, I get the following when I alert the width: NaN. This code works fine in Chrome.

Upvotes: 1

Views: 39

Answers (1)

dfsq
dfsq

Reputation: 193271

Since you have XML, not just HTML you should use childNodes and nodeValue:

width = parseFloat(doc.getElementsByTagName('width')[0].childNodes[0].nodeValue);

Upvotes: 1

Related Questions