XML : how to get all

Can anyone answer this question? this is actually my past year exam question. I do not really understand XML DOM as i am very new with XML. so, this is the question?

Given an XML document:

  <?xml version="1.0"?>  <breakfast-menu>      <food>            <name>Belgian Waffles</name>            <price>RM5.95</price>            <description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>            <calories>650</calories>      </food>      <food>            <name>Strawberry Belgian Waffles</name>            <price>RM7.95</price>            <description>Light Belgian Waffles covered with strawberry and whipped cream</description>            <calories>900</calories>      </food>  </breakfast-menu>    

Assume that by using Javascript DOM, the code above is read and stored in a variable named xmlDOM. Write Javascript DOM to do the following:

a)Get all elements and store in an array variable in allfoods.(2marks)

b)From the allfoods variable, get and display the price of the second food in the list.(2marks)

c)Display all food name and its calories.(6marks)

No comments:

Post a Comment