Given the following XML document, which two XPath expressions return the same result?
<?xml version =”1.0″ encoding =”UTF – 8″?>
<bookstore>
<book category=”COOKING”>
<title lang=”en”>Everyday Italian Treats</title>
<author>George Smith</author>
<year>2009</year>
<price>30.00</price>
</book>
<book category=”WEB”>
<title lang=”en”>Getting Started with XPath</title>
<author>Tammy Lee</author>
<author>SergieLadloff</author>
<year>2011</year>
<price>49.99</price>
</book>
</bookstore>
A. bookstore/book/author
B. bookstore/book/author/text ()
C. bookstore/book/author/*
D. bookstore//author/text ()
E. //author/@text
F. //author/*text
B,D
I confirm B,D answers are correct!
I checked my java class XPath parsing and this output:
Answer A bookstore/book/author[null, null, null]
Answer B bookstore/book/author/text()[George Smith, Tammy Lee, SergieLadloff]
Answer C bookstore/book/author/*[]
Answer D bookstore//author/text()[George Smith, Tammy Lee, SergieLadloff]
Answer E //author/@text[]
javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:612)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:147)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:180)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:268)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:390)
at XPathExample.evaluateXPath(XPathExample.java:66)
at XPathExample.main(XPathExample.java:49)
————— linked to ——————
javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:398)
at XPathExample.evaluateXPath(XPathExample.java:66)
at XPathExample.main(XPathExample.java:49)
Caused by: javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:612)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:147)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:180)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:268)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:390)
… 2 more
Answer F //author/*text[]
Output:
George Smith
George Smith
George Smith
BD
I confirmed B,D correct answers!
I checked with my class java parser XPath and then results:
Answer A bookstore/book/author[null, null, null]
Answer B bookstore/book/author/text()[George Smith, Tammy Lee, SergieLadloff]
Answer C bookstore/book/author/*[]
Answer D bookstore//author/text()[George Smith, Tammy Lee, SergieLadloff]
Answer E //author/@text[]
javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:612)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:147)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:180)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:268)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:390)
at XPathExample.evaluateXPath(XPathExample.java:66)
at XPathExample.main(XPathExample.java:49)
————— linked to ——————
javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:398)
at XPathExample.evaluateXPath(XPathExample.java:66)
at XPathExample.main(XPathExample.java:49)
Caused by: javax.xml.transform.TransformerException: Esistono altri token non validi: ‘text’
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:612)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:147)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:180)
at com.sun.org.apache.xpath.internal.XPath.(XPath.java:268)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:390)
… 2 more
Answer F //author/*text[]