Hi Jacob, The StAX API for the getAttributeValue(namespaceURI, localName) method says "Returns the normalized attribute value of the attribute with the namespace and localName If the namespaceURI is null the namespace is not checked for equality" (from the JDK 1.6 JavaDocs, which AFAIK reflects the current standard). This is the documented API, so it's what needs to be followed by the XMLStreamReader implementation - and the Spring implementation is broken because it doesn't check for null.
JiBX should really be passing the empty string in this case, rather than null - but if the XMLStreamReader implementation followed the documented interface the attribute would still be returned correctly, which is why I haven't seen any problems with attributes using other StAX readers. I've changed the JiBX code for 1.2.2 to pass an empty string, but you still should enter this as a bug against the Spring code. Thanks for tracking down through the details of what was going wrong, though I disagree with your conclusion. :-) - Dennis Dennis M. Sosnoski SOA and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 Jacob Metcalf wrote: > I am having a lot of difficulty getting the combination of JiBX > 1.1.6a/1.2.1, Woodstox Stax 3.2.1, Spring WS 1.5.6 and Spring Batch 2 > to parse attributes in an xml file which has no namespace. Whatever I > do I get the execption org.jibx.runtime.JiBXException: Missing > required attribute "testAttribute" Through debugging I think I have > tracked down the problem, and it revolves around the fact that the > JiBX generated code is looking for the attribute with a namespace of > null but trying to match against a QName returned by Woodstox which > contains the empty string "": - When I set a breakpoint in the > concrete implementation of: XMLStreamReader.getAttributeValue(String > namespaceURI, String localName) I see that the generated binding code > is calling this function with namespaceURI = null. - The concrete > implementation comes from spring-xml 1.5.6 - its > org.springframework.xml.stream.XmlEventStreamReader which is used to > turn an event reader into a stream reader (necessary because Spring > Batch takes a nifty fragment based approach to reading XML). This > compares the incoming namespareURI argument to the namespace in the > QName: / public String getAttributeValue(String namespaceURI, String > localName) { for (int i = 0; i < getAttributeCount(); i++) { QName > name = getAttributeName(i); if > (name.getNamespaceURI().equals(namespaceURI) && > name.getLocalPart().equals(localName)) { return getAttributeValue(i); > } } return null; }/ - Working through the StAX implementation it seems > that the w3c recommendation is that QName will contain the empty > string when no namespace is declared so what Woodstox does is correct: > / /** * > > Prefix to use to represent the default XML Namespace. > > * * > > Defined by the XML specification to be "". > > * * @see * Namespaces in XML, 3. Qualified Names > <http://www.w3.org/TR/REC-xml-names/#ns-qualnames> */ public static > final String DEFAULT_NS_PREFIX = "";/ So my question is, having > tracked down the problem, can anyone suggest an easy option for > working around this mismatch? I saw it was discussed here > <http://markmail.org/message/hblgqudv65tgc3lm>. However since I am > operating in Spring Batch (so am several steps removed) I will have to > rewrite quite a lot of classes in order to replace the Spring > implementation with a version which matches both null and "". I saw > some mention that there was some work being done on Spring > compatibility in JiBX 2.0 so I am hoping someone has already picked up > on this issue (hoping a lot since I am a big fan of both JiBX and > Spring). Hopefully I have identified the root cause of the issue in > detail. But here are the sources, starting with the XML file > example.xml <http://www.nabble.com/file/p23349737/example.xml> This is > my binding file test.jibx.xml > <http://www.nabble.com/file/p23349737/test.jibx.xml> This is my java: > SingleTest.java <http://www.nabble.com/file/p23349737/SingleTest.java> > ------------------------------------------------------------------------ > View this message in context: Mismatch between JiBX and QName > represntation of an attribute with no namespace? > <http://www.nabble.com/Mismatch-between-JiBX-and-QName-represntation-of-an-attribute-with-no-namespace--tp23349737p23349737.html> > Sent from the jibx-users mailing list archive > <http://www.nabble.com/jibx-users-f4287.html> at Nabble.com. > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users