users@jaxb.java.net

Preserving order on XML element attributes

From: Lagomasino, Adolfo (Adolfo) <"Lagomasino,>
Date: Tue, 30 Mar 2004 10:04:15 -0500

Is there a way to specify the order in which the XML element attributes will be written out in the marshalled file?

I have noticed that the order of the attributes in the output file seems to correspond to the order in which they are presented in the Javadoc description of the binding JAXB class. However, this order does not correspond with the order in the original schema. The attributes seem to be scrambled in an arbitrary order. I don't know where the scrambling takes place. I have tried changing the order of the attributes in the schema and I always get the same output.

To illustrate, here is a segment of the original schema. Note for example that the two required attributes are the first two attributes listed.
<xsd:element name="ViewObj">
        <xsd:complexType>
                <xsd:sequence>
                        <xsd:choice>
                                <xsd:element ref="ViewGroup" minOccurs="0" maxOccurs="unbounded"/>
                        </xsd:choice>
                        <xsd:element ref="ReqCapabilityConstraint" minOccurs="0"/>
                        <xsd:choice minOccurs="0">
                                <xsd:element ref="LogicalTable" minOccurs="0"/>
                        </xsd:choice>
                </xsd:sequence>
                <xsd:attribute name="votName" type="xs:string" use="required"/>
                <xsd:attribute name="Link-SvcObj" type="xs:string" use="required"/>
                <xsd:attribute name="votPerm" default="All">
                        <xsd:simpleType>
                                <xsd:restriction base="xs:NMTOKEN">
                                        <xsd:enumeration value="All"/>
                                        <xsd:enumeration value="Hidden"/>
                                        <xsd:enumeration value="None"/>
                                        <xsd:enumeration value="ReadOnly"/>
                                        <xsd:enumeration value="UpdateOnly"/>
                                </xsd:restriction>
                        </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute name="valBypass" default="false">
                        <xsd:simpleType>
                                <xsd:restriction base="xs:NMTOKEN">
                                        <xsd:enumeration value="true"/>
                                        <xsd:enumeration value="false"/>
                                </xsd:restriction>
                        </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute name="cwlClassName" type="xs:string"/>
                <xsd:attribute name="dynamicViewCondExpr" type="xs:string"/>
                <xsd:attribute name="valBypassList" type="xs:string"/>
                <xsd:attribute name="provisioningSequence" type="xs:string"/>
        </xsd:complexType>
</xsd:element>

And here is the same segment from the Javadoc of the binding JAXB object. Note that the same two required attributes are interspersed somehow.

 <element name="ViewObj">
   <complexType>
     <complexContent>
       <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
         <sequence>
           <choice>
             <element ref="{}ViewGroup" maxOccurs="unbounded" minOccurs="0"/>
           </choice>
           <element ref="{}ReqCapabilityConstraint" minOccurs="0"/>
           <choice minOccurs="0">
             <element ref="{}LogicalTable" minOccurs="0"/>
           </choice>
         </sequence>
         <attribute name="votPerm">
           <simpleType>
             <restriction base="{http://www.w3.org/2001/XMLSchema}NMTOKEN">
               <enumeration value="All"/>
               <enumeration value="Hidden"/>
               <enumeration value="None"/>
               <enumeration value="ReadOnly"/>
               <enumeration value="UpdateOnly"/>
             </restriction>
           </simpleType>
         </attribute>
         <attribute name="votName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
         <attribute name="cwlClassName" type="{http://www.w3.org/2001/XMLSchema}string" />
         <attribute name="provisioningSequence" type="{http://www.w3.org/2001/XMLSchema}string" />
         <attribute name="valBypassList" type="{http://www.w3.org/2001/XMLSchema}string" />
         <attribute name="valBypass">
           <simpleType>
             <restriction base="{http://www.w3.org/2001/XMLSchema}NMTOKEN">
               <enumeration value="true"/>
               <enumeration value="false"/>
             </restriction>
           </simpleType>
         </attribute>
         <attribute name="Link-SvcObj" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
         <attribute name="dynamicViewCondExpr" type="{http://www.w3.org/2001/XMLSchema}string" />
       </restriction>
     </complexContent>
   </complexType>
 </element>

The order of the attributes in the marshalled file correspond to this order. That's not the order I want though.

I realize the order of the attributes is not an XML issue. This is a human issue; our customers and field support look at the output file with a text editor (vi) and would like to have the attributes ordered in a specific way to help in debugging.

I am using JWSDP 1.2

Would appreciate any help on this

Adolfo Lagomasino

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net