Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2549

XPath with default namespace - No result

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.7.1
    • None
    • Xalan
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)

    Description

      Hi,

      I am having difficulties to use XPath query on a XML dataset having its root element with an xmlns attribute with no prefix.

      In that specific case, the XPath query does not return the value. Since I have no prefix for the namespace I simply can get the value.
      It this a known issue or am I simply doing something wrong ?

      Here is my XML :

      default-ns.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <report xmlns="http://www.mydomain.com/report">
          <account_number>123</account_number>
      </report>
      
          @Test
          public void xPathDefaultNS() throws XPathExpressionException {
              javax.xml.xpath.XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance();
              javax.xml.xpath.XPath xpath = factory.newXPath();
              javax.xml.xpath.XPathExpression expression = xpath.compile("/report/account_number");
              String result = expression.evaluate(new org.xml.sax.InputSource(this.getClass().getResourceAsStream("default-ns.xml")));
              Assert.assertTrue("123".equals(result));
          }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              olivier.roger Olivier Roger
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: