5

How do check 'roster' has no child values using javascript

<club code="3RD1" tvcode="">
   <name>3RD PLACE TEAM 1</name>
   <roster/>
</club>
<club code="3RD1" tvcode="">
   <name>3RD PLACE TEAM 1</name>
   <roster>
     <player code="AUQ"/>
   </roster>
</club>
1
  • Can you show your JavaScript effort? Commented May 9, 2013 at 11:16

1 Answer 1

4

if you can use jquery,

you can parse this by using $.parseXML

xmlDoc = $.parseXML( "<xml></xml>" );

and then you can use find to get the prefered node

$(xmlDoc).find("roster")

and get number of children via

.children().length

putting it together

var rostersChildren = $(xmlDoc).find("roster").children().length;
console.log(rostersChildren > 0);

here is a sample fiddle.

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

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.