2010-11-15 60 views
3

我使用的是Apache的Xerces2-j來解析我的XSD。我正在嘗試獲取XSD中元素/屬性聲明的數據類型信息。Xerces2-j XML模式屬性/元素聲明數據類型

下面是一個例子XSD:

<xs:element name="Pretzel"> 
    ... 
    <xs:attribute name="Flavor" type="xs:string"/> 
    <xs:attribute name="ProductID" type="xs:nonNegativeInteger"/> 
    ... 
</xs:element> 

在這種情況下,我想獲得風味的ProductID屬性的數據類型。根據W3C Schema APIits Xerces2-j implementation,XSAttributeDeclaration的getActualVCType()會得到我想要的。但對我來說,該方法總是返回45,這是UNAVAILABLE_DT。這是Xerces2-j中的錯誤,還是我只是理解API錯誤?如果我是,我會很感激,如果有人能指出我在這裏正確的方向。

+0

碰撞。沒人知道? :( – 2010-11-17 14:19:19

回答

0

您正在尋找使用方法

XSAttributeDeclaration.getTypeDefinition(); // returns XSSimpleTypeDefinition 

簡單的類型和/或可能

複雜類型。

的方法getActualVCType()已被棄用,其替代呼叫getValueConstraintValue()。getActualValueType()查找到一個所謂的value constraint 這是不是你在找什麼。這種說法也由代碼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的方法,它看起來很有希望。

相關問題