« Return to Thread: Duplicated namespace declaration from output xml

Re: Duplicated namespace declaration from output xml

by Son Nguyen :: Rate this Message:

Reply to Author | View in Thread

I was able to create a similar situation using a smaller schema so that it is to reproduce.

Here is the schema: Book.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">


<xs:element name="Collection">
   <xs:complexType>
      <xs:sequence>
        <xs:element name ="books">
           <xs:complexType>
              <xs:sequence>
                <xs:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
              </xs:sequence>
           </xs:complexType>
        </xs:element>
      </xs:sequence>
   </xs:complexType>
</xs:element>

<xs:complexType name="bookType">
  <xs:sequence>
    <xs:element name="name" type="xs:anySimpleType" minOccurs="0"/>
    <xs:element name="ISBN" type="xs:anySimpleType" minOccurs="0"/>
    <xs:element name="price" type="xs:anySimpleType" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>

</xs:schema>


The output:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Collection>
    <books>
        <book>
            <name xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">ABC</name>
        </book>
    </books>
</Collection>


I think the problem comes from the xs:anySimpleType. If I change it to string, it will works as normal. It also make sense that jaxb create output with types for anySimpleType element. However, it will be a lot nicer if jaxb can group all the xml declaration on the top and just use the nametag for it. Do you know a way to tell jaxb to do that?

Attachment is the complete project for you to run.

Thanks,

 « Return to Thread: Duplicated namespace declaration from output xml