|
INTERVIEW QUESTIONS
XML
E4X
DETAILS
Question: How to use of E4X with XML?
Answer: Using E4X we can easily use JAvAScript with an XML. Example: I have written an XML document. <order> <date>2009-26-01</date> <customer> <firstname>Porus</firstname> <lastname>Jain</lastname> </customer> <item> <name>Milk</name> <qty>4</qty> <price>100.00</price> </item> </order> We can stroe this XML document as an string in variable order. var order = new XML(txt) 'or' Assign the XML text to the XML object variable directly. var order = new XML() order=<order id="010"> <date>2009-26-01</date> <customer> <firstname>Porus</firstname> <lastname>Jain</lastname> </customer> <item> <name>Milk</name> <qty>4</qty> <price>100.00</price> </item> </order> We can also calculate the price like that, var total=order.item.qty * order.item.price
Can we display the customers full name like that, document.write(order.customer.lastname) document.write(",") document.write(order.customer.firstname)
Can add new items like that, order.item+= <item> <name>Bread</name> <qty>5</qty> <price>70.00</price> </item>
We can display the order id like that, document.write(order.@id)
We can calculate the total price, when the order has many items like that, var price=0 for each (i in order.item) { price+= i.qty*i.price }
|
|
|
Category |
E4X Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7622 users |
Added on |
4/28/2014 |
Views |
71287 |
Rate it! |
|
|
Question:
How to use of E4X with XML?
Answer:
Using E4X we can easily use JAvAScript with an XML. Example: I have written an XML document. <order> <date>2009-26-01</date> <customer> <firstname>Porus</firstname> <lastname>Jain</lastname> </customer> <item> <name>Milk</name> <qty>4</qty> <price>100.00</price> </item> </order> We can stroe this XML document as an string in variable order. var order = new XML(txt) 'or' Assign the XML text to the XML object variable directly. var order = new XML() order=<order id="010"> <date>2009-26-01</date> <customer> <firstname>Porus</firstname> <lastname>Jain</lastname> </customer> <item> <name>Milk</name> <qty>4</qty> <price>100.00</price> </item> </order> We can also calculate the price like that, var total=order.item.qty * order.item.price
Can we display the customers full name like that, document.write(order.customer.lastname) document.write(",") document.write(order.customer.firstname)
Can add new items like that, order.item+= <item> <name>Bread</name> <qty>5</qty> <price>70.00</price> </item>
We can display the order id like that, document.write(order.@id)
We can calculate the total price, when the order has many items like that, var price=0 for each (i in order.item) { price+= i.qty*i.price } Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Tell me how can we use E4X in Mozilla and Mozilla Based browers?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All E4X Interview Questions & Answers - Exam Mode /
Learning Mode
|