Which two XPath expressions return the same result?

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

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “Which two XPath expressions return the same result?

  1. 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[]

    1. 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[]

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.