Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6355823

Example in javax.xml.xpath package.html should use NodeList instead of NodeSet

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • xml
    • b64
    • sparc
    • solaris_10

      The following example in the package docs for javax.xml.xpath:

      XPath xpath = XPathFactory.newInstance().newXPath();
      String expression = "/widgets/widget";
      InputSource inputSource = new InputSource("widgets.xml");
      NodeSet nodes = (NodeSet) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);

      is incorrect. The return value of xpath.evaluate should be cast to a NodeList, not a
      NodeSet. Fix is:

      XPath xpath = XPathFactory.newInstance().newXPath();
      String expression = "/widgets/widget";
      InputSource inputSource = new InputSource("widgets.xml");
      NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);

            nwalshsunw Norman Walsh (Inactive)
            mullan Sean Mullan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: