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  http://www.w3.org/TR/REC-xml-names/#ns-qualnames 
     * Namespaces in XML, 3. Qualified Names 
     */
    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  http://markmail.org/message/hblgqudv65tgc3lm here .
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 

http://www.nabble.com/file/p23349737/example.xml example.xml 

This is my binding file 

http://www.nabble.com/file/p23349737/test.jibx.xml test.jibx.xml 

This is my java:

http://www.nabble.com/file/p23349737/SingleTest.java SingleTest.java 
-- 
View this message in context: 
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 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

Reply via email to