1

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.

2
  • @ArunprasanthKV: please note that inline code spans (like this) should not be used for emphasis. Also, please try and improve the post as much as you can when editing. See the editing guidelines for more information. Thanks! Commented Feb 23, 2015 at 9:33
  • @Qantas94Heavy sure i will have a look at this, thanks for your valid informations Commented Feb 23, 2015 at 9:44

1 Answer 1

1

try with this

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book")[0];

console.log(x.hasAttribute("category"))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.