[
https://issues.apache.org/jira/browse/WSCOMMONS-557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901213#action_12901213
]
Andreas Veithen commented on WSCOMMONS-557:
-------------------------------------------
The proposed fix is not correct, as can be shown with the following test case:
public void testAttributes2() throws Exception {
DOMTestUtil.execute(new DOMTestUtil.Test() {
public void execute(DocumentBuilderFactory dbf) throws Exception {
Document doc = dbf.newDocumentBuilder().parse(new
InputSource(new StringReader(
"<root><child xmlns=\"\"/></root>")));
Element element =
(Element)doc.getDocumentElement().getFirstChild();
assertTrue(element.hasAttributes());
}
});
}
I think that the correct fix should actually be much easier. I believe that the
parentHasSameDefaultNS thing in ElementImpl#getAttributes() is just a hack to
work around an issue that I've solved in r763831 (which caused StAXOMBuilder to
add a namespace declaration to every element without prefix, event if no such
declaration is present in the document being parsed). Probably the code should
just produce an AttrImpl for every entry in the namespaces map, without doing
some fancy sort of inspection on the parent element.
> org.apache.axiom.om.impl.dom.ElementImpl class's hasAttributes() and
> getAttributes() methods are not compatible with DOM interfaces.
> ------------------------------------------------------------------------------------------------------------------------------------
>
> Key: WSCOMMONS-557
> URL: https://issues.apache.org/jira/browse/WSCOMMONS-557
> Project: WS-Commons
> Issue Type: Bug
> Components: AXIOM
> Affects Versions: Axiom 1.2.10
> Environment: Ubuntu, JDK 1.6
> Reporter: Amila Jayasekara
> Assignee: Andreas Veithen
> Attachments: WSCOMMONS-557.diff
>
>
> The class org.apache.axiom.om.impl.dom.ElementImpl implements both DOM
> Element and OMElement interfaces. According to DOM API the method
> hasAttrbutes() should return true if there are attributes attached to current
> node. Also this method will return true if there are namespaces attached to
> current node. But according to current implementation the ElementImpl class
> only checks for namespace nullability. This code will fail if we have a xml
> like follows,
> <?xml version='1.0' encoding='utf-8'?>
> <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
> wsu:Id="Id-739587016">
> <GetDirectionsResponse xmlns="http://www.example.org/webservices/">
> <GetDirectionsResult>
> <drivingdirections xmlns="">
> <route distanceToTravel="500m" finalStep="false" id="0">Head south on
> Grove St</route>
> </drivingdirections>
> </GetDirectionsResult>
> </GetDirectionsResponse>
> </soapenv:Body>
> In above xml the node "drivingdirections" is having an empty namespace. But
> for "drivingdirections" node, the method "hasAttribute()" should return true,
> as there is a namespace attached to it. But current implementation of
> ElementImpl returns false.
> Also getAttributes() method should return empty namespace ("xmlns=\"\"") for
> "drivingdirections" node. Current implementation doesnt return empty
> namespace as an attribute. Since namespace of drivingdirections is empty,
> namespace of child elements of "drivingdirections" are also null. Therefore
> hasAttribute() method will return false for even elements like "route".
> ("route" element has attributes, therefore hasAttribute() should return true)
> There are 2 rampart issues which depends on this.
> [1] https://issues.apache.org/jira/browse/RAMPART-303
> [2] https://issues.apache.org/jira/browse/RAMPART-128
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.