check XML node exists or not using javascript -


how 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> 

if can use jquery,

you can parse using $.parsexml

xmldoc = $.parsexml( "<xml></xml>" ); 

and can use find prefered node

$(xmldoc).find("roster") 

and number of children via

.children().length 

putting together

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

here sample fiddle.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -