我使用Apache的Xerces2-j解析我的XSD。我试图获取XSD中元素/属性声明的数据类型信息。
下面是一个XSD示例:
<xs:element name="Pretzel">
...
<xs:attribute name="Flavor" type="xs:string"/>
<xs:attribute name="ProductID" type="xs:nonNegativeInteger"/>
...
</xs:element>在本例中,我希望获得Flavor和ProductID属性的数据类型。根据W3C模式API和它的Xerces2-j实现,XSAttribute宣言的getActualVCType()将得到我想要的东西。但是对我来说,这个方法总是返回45,即UNAVAILABLE_DT.这是Xerces2-j中的一个bug,还是我只是理解了API错误?如果是的话,如果有人能给我指明正确的方向,我将不胜感激。
发布于 2011-02-17 03:57:51
您希望使用该方法。
XSAttributeDeclaration.getTypeDefinition(); // returns XSSimpleTypeDefinition对于简单类型和/或可能的
XSAttributeDeclaration.getEnclosingCTDefinition(); // returns XSComplexTypeDefinition对于复杂的类型。
方法getActualVCType()是不推荐的,它的替代调用getActualVCType查找的是一个所谓的价值约束,而这不是您要寻找的。XSAttributeDecl.java中的代码也支持此参数。
// variable definition
48 // value constraint type: default, fixed or !specified
49 short fConstraintType = XSConstants.VC_NONE;和
183 public short getActualVCType() {
184 return getConstraintType() == XSConstants.VC_NONE ?
185 XSConstants.UNAVAILABLE_DT :
186 fDefault.actualValueType;
187 }使用
136
137 public short getConstraintType() {
138 return fConstraintType;
139 }建议您确实获得UNAVAILABLE_DT,因为它没有设置。我建议研究一下XSSimpleTypeDefinition的方法,它在我看来是很有前途的。
https://stackoverflow.com/questions/4186015
复制相似问题