我有一个简单的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;
}
但我得到'十进制'作为baseType名称,但它实际上是一个xs:integer。它进入 'XSFacet.FACET_MAXLENGTH' else 部分在方法 parseSimpleType()?? 中定义。如何将整数作为 complexType 的基本类型?