Reputation: 267
I have a simple 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>
I am trying the retrieve base type of the complexType 'shoetype' using the following code
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;
}
but I am getting 'decimal' as the baseType name, but its actually an xs:integer. Its getting into 'XSFacet.FACET_MAXLENGTH' else part defined in the method parseSimpleType()??. How will I get integer as the baseType of the complexType?
Upvotes: 0
Views: 739
Reputation: 356
The posted code walks base type links from xs:integer to xs:decimal; only the latter is primitive. It seems a case of wrong expectations: in XML Schema terminology, not all built-in types are actually primitive.
See the convenient diagram in the XML Schema standard for further details.
Upvotes: 0