2011-12-29 32 views
0

我有一個簡單的xsd獲取錯誤XSOM BASETYPE的XSSimpleType

<xs:element name="shoesize" type="shoetype"/> 
<xs:complexType name="shoetype"> 
<xs:simpleContent> 
<xs:extension base="xs:integer"> 
    <xs:attribute name="country" type="attrType" /> 
</xs:extension> 
</xs:simpleContent> 
</xs:complexType> 

<xs:simpleType name="attrType"> 
<xs:restriction base="xs:string"> 
    <xs:enumeration value="abc" /> 
    <xs:enumeration value="xyz" /> 
</xs:restriction> 
</xs:simpleType> 

我想要檢索的複雜類型「shoetype」的基本類型使用下面的代碼

void parseComplexType(XSComplexType xsComplexType, StringBuffer stringBuffer) { 
    XSContentType xsContentType = xsComplexType.getContentType(); 
    if (xsContentType != null) { 
     XSParticle xsParticle = xsContentType.asParticle(); 
     if (xsParticle != null) { 
      parseParticle(xsParticle, stringBuffer); 
     } else if (xsContentType.asSimpleType() != null) { 
      stringBuffer.append(parseSimpleType(xsContentType.asSimpleType())); 
     } 
    } 
    return; 
} 

String parseSimpleType(XSSimpleType xsSimpleType) { 
    if (xsSimpleType.isPrimitive()) { 
     return(xsSimpleType.getName()); 
    } 
    if (xsSimpleType.asRestriction() != null) { 
     XSRestrictionSimpleType xsRestrictionSimpleType = xsSimpleType.asRestriction(); 
     Iterator<XSFacet> facetIterator = xsRestrictionSimpleType.iterateDeclaredFacets(); 
     if (facetIterator != null) { 

      // Special Case 
      if (!facetIterator.hasNext()) { 
       return xsSimpleType.getBaseType().getName(); 
      } 
      StringBuffer strBuffer = new StringBuffer(); 
      strBuffer.append("["); 
      while (facetIterator.hasNext()) { 
       XSFacet xsFacet = facetIterator.next(); 
       if (xsFacet.getName().equals(XSFacet.FACET_ENUMERATION)) { 
        strBuffer.append(xsFacet.getValue() + (facetIterator.hasNext() ? "/" : "")); 
       } else if (xsFacet.getName() 
         .equals(XSFacet.FACET_MAXLENGTH)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_FRACTIONDIGITS)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_MINEXCLUSIVE)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_MAXEXCLUSIVE)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_MININCLUSIVE)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_MAXINCLUSIVE)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_LENGTH)) { 
        strBuffer.append(xsSimpleType.getBaseType().getName()); 
        break; 
       } else if (xsFacet.getName().equals(
         XSFacet.FACET_WHITESPACE)) { 

        // ignore 
        break; 
       } else { 

        // Log this type 
        System.out.println(xsFacet.getName()); 
       } 
      } 
      strBuffer.append("]"); 
      return strBuffer.toString(); 
     } 
    } if (xsSimpleType.asComplexType() != null) { 
     StringBuffer stBuffer = new StringBuffer(); 
     parseComplexType(xsSimpleType.asComplexType(), stBuffer); 
     return stBuffer.toString(); 
    } 
    return null; 
} 

但我正在逐漸'decimal'作爲baseType名稱,但它實際上是一個xs:integer。它進入'XSFacet.FACET_MAXLENGTH'其他部分,在方法parseSimpleType()??中定義。 如何獲得整數作爲complexType的baseType?

回答

0

發佈的代碼將基本類型鏈接從xs:integer鏈接到xs:decimal;只有後者是原始的。這似乎是錯誤的期望:在XML Schema術語中,並非所有的內置的類型實際上都是原始的

查看方便diagram in the XML Schema standard瞭解更多詳情。