See if xml has attribute and value



I have some xml that looks like this



<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<menu>
<day name="monday">
<meal name="BREAKFAST">
<counter name="Hot Cereal">
<dish>
<name>Oatmeal</name>
</dish>
</counter>
</meal>
</day>
</menu>
</body>
</html>


I have shortened the xml for this example to make it simpler. Now in javascript I want to check if this xml has value and tags after the meal tag.I am using sax.js xml parser and xmlreader.js to read the xml. Now here is what I have and I am very confused why it is not returning true?


I read the xml and save it as var res And then to check whether there are values and tags after meal tag I do this.



if (res.html.body.menu.day.at(dayNumber).meal) {
console.log('IT IS TRUE');
}


And it should come true for this xml correct, but it is not what am I missing?


Thanks for the help in advance.


No comments:

Post a Comment