Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

XML Attribute Question

I have a xml file like this...
<?xml version="1.0" encoding="utf-8" ?>
<PartialRates>
  <partialRates rate1="18 cents" rate2="16 cents" rate3="8 cents" rate4="9 cents" rate5="10 cents"></partialRates>
</PartialRates>

Is there a DOM function to get the number of elements in the attribute "partialRates" ?

What I need is ... there are 5 rates in the above line. I want a javascript function to return
5.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
as angelIII said: use the length.  Sample javascript you could use:

// get the tag - iif you add a class or id you could get a specific tag
// this gets the first one matched.

var rates = document.getElementsByTagName('partialRates ')[0];
var length = rates.attributes.length;  // this returns 5
Avatar of prain

ASKER

Thanks. Great!.