Consider the XML file: <purse> <coin> <value>0.5</value> <name lang=”en”>half do
ID: 3688817 • Letter: C
Question
Consider the XML file:
<purse>
<coin>
<value>0.5</value>
<name lang=”en”>half dollar</name>
</coin>
<coin>
<value>0.25</value>
<name lang=”en”>quarter</name>
</coin>
</purse>
What are the values of the following XPath expressions?
a.
/purse/coin[1]/value
b.
/purse/coin[2]/name
c.
/purse/coin[2]/name/@lang
d.
name(/purse/coin[2]/*[1])
e.
count(/purse/coin)
f.
count(/purse/coin[2]/name)
a.
/purse/coin[1]/value
b.
/purse/coin[2]/name
c.
/purse/coin[2]/name/@lang
d.
name(/purse/coin[2]/*[1])
e.
count(/purse/coin)
f.
count(/purse/coin[2]/name)
Explanation / Answer
QUESTION ANSWER
A. 0.5(1ST value of purse)
B. QUARTER(name of second value in purse)
C. EN(using attributes ,value of lang attribute in name)
D. value
e. 2
f. 1
you can follow the tutorial for this xpath at : http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/