【问题标题】:Xerces "fixed" element attribute in XML SchemaXerces XML Schema 中的“固定”元素属性
【发布时间】:2016-09-18 11:54:05
【问题描述】:

我有一个如下定义的 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 有关,但我无法弄清楚我需要调用哪些方法来提取这些信息。有人可以指出我正确的方向吗?谢谢!

【问题讨论】:

    标签: java xsd xerces


    【解决方案1】:

    我能够解决它。结果我需要在 XSElementDeclaration 上调用 getConstraintType(),它返回 XSConstants.VC_NONE、VC_DEFAULT 或 VC_FIXED。然后,如果约束类型为 not none,则通过调用 getValueConstraintValue().getActualValue() 访问该值。例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多