You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Olivier Roger (Commented) (JIRA)" <xa...@xml.apache.org> on 2012/02/08 11:30:59 UTC
[jira] [Commented] (XALANJ-2549) XPath with default namespace - No
result
[ https://issues.apache.org/jira/browse/XALANJ-2549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13203446#comment-13203446 ]
Olivier Roger commented on XALANJ-2549:
---------------------------------------
I also tried other queries without success, like:
# javax.xml.xpath.XPathExpression expression = xpath.compile("/*[local-name()='report']/account_number");
# javax.xml.xpath.XPathExpression expression = xpath.compile("/*[local-name()='report' and namespace-uri()='http://www.mydomain.com/report']/account_number");
Removing the *xmlns attribute* from the report tag allows me to find the correct result but is not my use case.
Adding a prefix to the namespace and using it also allows me to find the correct result but is not my use case either.
> XPath with default namespace - No result
> ----------------------------------------
>
> Key: XALANJ-2549
> URL: https://issues.apache.org/jira/browse/XALANJ-2549
> Project: XalanJ2
> Issue Type: Bug
> Security Level: No security risk; visible to anyone(Ordinary problems in Xalan projects. Anybody can view the issue.)
> Components: Xalan
> Affects Versions: 2.7.1
> Reporter: Olivier Roger
> Labels: xalan, xpath
>
> 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 :
> {noformat:title=default-ns.xml}
> <?xml version="1.0" encoding="UTF-8"?>
> <report xmlns="http://www.mydomain.com/report">
> <account_number>123</account_number>
> </report>
> {noformat}
> {code}
> @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));
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org