2016-09-18 32 views
1

「固定的」元件屬性我有一個XML模式元素定義如下:的Xerces在XML模式

<xsd:element name="Test"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="ElementFixed" fixed="SomeFixedValue"/> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

據我所知,「ElementFixed」是通配符元素。 (因爲沒有類型定義,它的類型是「anyType」)。

現在也許這是相關或不相關的(對於元素是通配符),但我試圖提取「固定」值「SomeFixedValue 「使用Xerces庫,並正在努力研究如何做到這一點。我懷疑它可能與XSAttributeUse或XSAttributeDeclaration有關,但我無法弄清楚需要調用哪些對象來提取此信息的方法。有人可以請指點我正確的方向嗎?謝謝!

回答

0

我能夠解決這個問題。原來我需要在XSElementDeclaration上調用getConstraintType(),它返回XSConstants.VC_NONE,VC_DEFAULT或VC_FIXED。然後,如果約束類型爲而不是無,則通過調用getValueConstraintValue()。getActualValue()來訪問該值。例如:

short vcKind = xsElementDecl.getConstraintType(); 
System.out.println("Constraint Type: " + vcKind); 
if (vcKind != XSConstants.VC_NONE) { 
    System.out.println("Value: " + xsElementDecl.getValueConstraintValue().getActualValue()); 
}