我有一个 XML 架构元素定义如下:
<xsd:element name="Test">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ElementFixed" fixed="SomeFixedValue"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
据我了解,“ElementFixed”是一个通配符元素。 (由于没有定义类型,因此它的类型为“anyType”。)
现在,这可能是相关或不相关的(与作为通配符的元素),但我正在尝试使用 Xerces 库提取“固定”值“SomeFixedValue”,并且正在努力找出如何做到这一点。我怀疑它可能与 XSAttributeUse 或 XSAttributeDeclaration 有关,但我无法弄清楚需要对哪些对象调用哪些方法来提取此信息。有人可以指出我正确的方向吗?谢谢!
最佳答案
我能够解决这个问题。结果我需要在 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());
}
关于java - XML 架构中的 Xerces "fixed"元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39557380/