jaxb
  1. jaxb
  2. JAXB-869

Multiple <any /> elements on a schema : second element is not loaded

    Details

    • Type: Bug Bug
    • Status: In Progress
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.2.5
    • Component/s: runtime
    • Labels:
      None

      Description

      An XML schema is mapped via JAXB to java objects with multiple <any /> elements. When unmarshalling an XML file which is compliant to this schema the object corresponding to the second <any /> element (and so on) is always null.

      Here is the portion of the XML schema :

      <complexType name="entry">
      <sequence>
      <any />
      <any />
      </sequence>
      </complexType>

      Here is the portion of the JAXB customization file :

      <bindings node="xs:complexType[@name='entry']/xs:sequence">
      <bindings node="xs:any[1]">
      <property name="key" />
      </bindings>
      <bindings node="xs:any[2]">
      <property name="value" />
      </bindings>
      </bindings>

      Here is the portion of the XML file :

      <entry>
      <boolean>true</boolean> <!-- loaded -->
      <boolean>false</boolean> <!-- never loaded -->
      </entry>

        Activity

        Hide
        Martin Grebac added a comment -

        There's no way to figure out where does the first 'any' content ends, thus the behaviour.

        Show
        Martin Grebac added a comment - There's no way to figure out where does the first 'any' content ends, thus the behaviour.
        Hide
        Bruno Kerrien added a comment - - edited

        Sorry to add a comment to a closed issue, but I don't get your answer and, thus, I don't understand why the issue was closed without any real fix.

        In the example given by sergiomail, the 2 any elements are declared in the XSD without giving any information about the minOccurs and maxOccurs properties, so the default values apply for these properties, i.e. minOccurs="1" and maxOccurs="1". So, the given XSD is equivalent to the following:

        <complexType name="entry">
           <sequence>
              <any minOccurs="1" maxOccurs="1" />
              <any minOccurs="1" maxOccurs="1" />
           </sequence>
        </complexType>
        

        Now, looking at the XML example given by sergiomail for this XSD, there is absolutely no ambiguity about where the first any content ends: it ends where the first <boolean> tag ends (and we know that the second <boolean> tag corresponds to the second any element).

        Maybe I'm missing something (I'm not an XML/XSD guru) but this is how I understand the W3C's XML Schema specifications.

        The fact that JAXB treats a sequence of 2 any elements with minOccurs=maxOccurs=1 as if it was a single unbounded any element is a major issue. As far as I'm concerned, I have the same kind of case in a XSD (i.e. a sequence of 2 any elements with minOccurs=maxOccurs=1) and I'm trying to use the XJC simple mode with a binding customization in order to generate one property with a given name for the first any element and one property with another name for the second any element, but XJC complains because having 2 property bindings for what it detects as a single any element (instead of 2) looks erroneous to it.

        To be clearer, here is the XSD and the binding customization I'm trying to use:

        test.xsd
        <?xml version="1.0" encoding="UTF-8"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        
           <xs:element name="Document" type="DocumentType"/>
          
           <xs:complexType name="DocumentType">
              <xs:sequence>
                 <xs:any processContents="lax"/>
                 <xs:any processContents="lax"/>
              </xs:sequence>
           </xs:complexType>
          
        </xs:schema>
        
        binding.xjb
        <?xml version="1.0" encoding="UTF-8"?>
        <jaxb:bindings version="2.1"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
           jaxb:extensionBindingPrefixes="xjc">
           
           <jaxb:globalBindings>
              <xjc:simple/>
           </jaxb:globalBindings>
            
           <jaxb:bindings schemaLocation="test.xsd">
            
              <jaxb:schemaBindings>
                 <jaxb:package name="test"/>
              </jaxb:schemaBindings>
               
              <jaxb:bindings node="xs:complexType[@name='DocumentType']/xs:sequence">
                 <jaxb:bindings node="xs:any[1]">
                    <jaxb:property name="first"/>
                 </jaxb:bindings>
                 <jaxb:bindings node="xs:any[2]">
                    <jaxb:property name="second"/>
                 </jaxb:bindings>
              </jaxb:bindings>
               
           </jaxb:bindings>
            
        </jaxb:bindings>
        

        And here is the XJC output when trying to generate the classes:

        parsing a schema...
        [ERROR] compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings.
          line 22 of file:/C:/Temp/binding.xjb
        
        [ERROR] (the above customization is attached to the following location in the schema)
          line 8 of file:/C:/Temp/test.xsd
        
        Failed to parse a schema.
        

        If I comment out the 2 property bindings in the binding.xjb customization, then there's no more error, but the 2 any elements are generated as a single property named anies, of type List<Object>, instead of 2 properties of type Object.

        I understand it's not the same issue as the original one, but I guess these 2 issues are linked. What is your point of view about this?

        Show
        Bruno Kerrien added a comment - - edited Sorry to add a comment to a closed issue, but I don't get your answer and, thus, I don't understand why the issue was closed without any real fix. In the example given by sergiomail, the 2 any elements are declared in the XSD without giving any information about the minOccurs and maxOccurs properties, so the default values apply for these properties, i.e. minOccurs="1" and maxOccurs="1" . So, the given XSD is equivalent to the following: <complexType name= "entry" > <sequence> <any minOccurs= "1" maxOccurs= "1" /> <any minOccurs= "1" maxOccurs= "1" /> </sequence> </complexType> Now, looking at the XML example given by sergiomail for this XSD, there is absolutely no ambiguity about where the first any content ends: it ends where the first <boolean> tag ends (and we know that the second <boolean> tag corresponds to the second any element). Maybe I'm missing something (I'm not an XML/XSD guru) but this is how I understand the W3C's XML Schema specifications. The fact that JAXB treats a sequence of 2 any elements with minOccurs=maxOccurs=1 as if it was a single unbounded any element is a major issue. As far as I'm concerned, I have the same kind of case in a XSD (i.e. a sequence of 2 any elements with minOccurs=maxOccurs=1 ) and I'm trying to use the XJC simple mode with a binding customization in order to generate one property with a given name for the first any element and one property with another name for the second any element, but XJC complains because having 2 property bindings for what it detects as a single any element (instead of 2) looks erroneous to it. To be clearer, here is the XSD and the binding customization I'm trying to use: test.xsd <?xml version= "1.0" encoding= "UTF-8" ?> <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" > <xs:element name= "Document" type= "DocumentType" /> <xs:complexType name= "DocumentType" > <xs:sequence> <xs:any processContents= "lax" /> <xs:any processContents= "lax" /> </xs:sequence> </xs:complexType> </xs:schema> binding.xjb <?xml version= "1.0" encoding= "UTF-8" ?> <jaxb:bindings version= "2.1" xmlns:jaxb = "http://java.sun.com/xml/ns/jaxb" xmlns:xjc = "http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs = "http://www.w3.org/2001/XMLSchema" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" jaxb:extensionBindingPrefixes= "xjc" > <jaxb:globalBindings> <xjc:simple/> </jaxb:globalBindings> <jaxb:bindings schemaLocation= "test.xsd" > <jaxb:schemaBindings> <jaxb:package name= "test" /> </jaxb:schemaBindings> <jaxb:bindings node= "xs:complexType[@name='DocumentType']/xs:sequence" > <jaxb:bindings node= "xs:any[1]" > <jaxb:property name= "first" /> </jaxb:bindings> <jaxb:bindings node= "xs:any[2]" > <jaxb:property name= "second" /> </jaxb:bindings> </jaxb:bindings> </jaxb:bindings> </jaxb:bindings> And here is the XJC output when trying to generate the classes: parsing a schema... [ERROR] compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings. line 22 of file:/C:/Temp/binding.xjb [ERROR] (the above customization is attached to the following location in the schema) line 8 of file:/C:/Temp/test.xsd Failed to parse a schema. If I comment out the 2 property bindings in the binding.xjb customization, then there's no more error, but the 2 any elements are generated as a single property named anies , of type List<Object> , instead of 2 properties of type Object . I understand it's not the same issue as the original one, but I guess these 2 issues are linked. What is your point of view about this?
        Hide
        Martin Grebac added a comment -

        Actually, you're right, thanks for exact clarification. I'm reopening and reassigning.

        Show
        Martin Grebac added a comment - Actually, you're right, thanks for exact clarification. I'm reopening and reassigning.
        Hide
        Bruno Kerrien added a comment -

        Thanks a lot, Martin.

        Show
        Bruno Kerrien added a comment - Thanks a lot, Martin.

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            Sergio
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: