2014-04-01 60 views
0

的XML混合內容的順序我有這樣的模式:確定衍生

<xsd:complexType name="ContentType" mixed="true"> 
     <xsd:annotation> 
     <xsd:documentation><![CDATA[ 
      The content type is a broad base type allowing any content. 
     ]]></xsd:documentation> 
     </xsd:annotation> 
     <xsd:complexContent> 
     <xsd:extension base="BaseContentType"> 
      <xsd:sequence> 
       <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" 
       /> 
      </xsd:sequence> 
      <xsd:attribute name="orientation" type="OrientationEnum" use="optional" 
       default="portrait"> 
       <xsd:annotation> 
        <xsd:documentation><![CDATA[ 
        The @orientation attribute is used to specify a "landscape" 
        orientation for the published form. This is primarily used 
        for schedules or for tables.     
        ]]></xsd:documentation> 
       </xsd:annotation> 
      </xsd:attribute> 
     </xsd:extension> 
     </xsd:complexContent> 
    </xsd:complexType> 

我使用XJC命令行工具來生成從上述模式中的Java類和類生成如下:

public abstract class BaseContentType { 

    @XmlMixed 
    protected List<Serializable> content; 
    @XmlAttribute(name = "id") 
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 
    @XmlID 
    @XmlSchemaType(name = "ID") 
    protected String id; 

public class ContentType 
    extends BaseContentType 
{ 

    @XmlMixed 
    @XmlAnyElement(lax = true) 
    @OverrideAnnotationOf 
    protected List<Object> contentOverrideForContentType; 

當我解組,所有的嵌套的XML元素得到珀普在ContentType對象的列表contentOverrideForContentType中,並且所有文本元素都被填充到列表contentBaseContentType中。

如何確定文本元素相對於嵌套元素的順序並構造整個文本?

我想獲取ContentType內的全部文本,我必須查看頂層文本和所有嵌套標記的文本並將它們全部合併(這裏是我需要知道順序的位置)。有沒有更好的方法來提取ContentType中的所有文本?

謝謝!

編輯 這與this的問題有關。

回答

0

如果聲明具體JAXB類propOrder可以指定對象將出現在XML

e.g. 
@XmlType(propOrder = { 
     "firstObjectName", 
     "fsecondObjectName" 
    }) 

記下訂單:使用propOrder當對象中的所有元素必須被添加到propOrder 。

0

我有同樣的問題,我發現元素將按照元素添加到列表中的順序進行排序......假設您正在使用有序列表(List,ArrayList .. )