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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 6
    • Affects Version/s: 6
    • Component/s: 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);

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: