【问题标题】:Getting wrong XSOM baseType for a XSSimpleType为 XSSimpleType 获取错误的 XSOM baseType
【发布时间】:2012-05-24 19:51:10
【问题描述】:

我有一个简单的xsd

<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>

我正在尝试使用以下代码检索 complexType '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;
}

但我将“十进制”作为基本类型名称,但它实际上是一个 xs:integer。它进入 'XSFacet.FACET_MAXLENGTH' else 部分在方法 parseSimpleType()?? 中定义。 如何将整数作为 complexType 的基本类型?

【问题讨论】:

    标签: java xsom


    【解决方案1】:

    发布的代码将基类型链接从 xs:integer 遍历到 xs:decimal;只有后者是原始的。这似乎是一个错误的预期:在 XML Schema 术语中,并非所有的内置类型实际上都是原始

    查看方便的diagram in the XML Schema standard了解更多详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多