Xml XSD模式中的嵌入式验证

Xml XSD模式中的嵌入式验证,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,我希望在XSD模式定义中嵌入有关如何使用元素的可选属性的规则。考虑以下元素定义: <xs:complexType name="sampleElement"> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="description" type="xs:string" use="optional"/> <xs:attribute nam

我希望在XSD模式定义中嵌入有关如何使用元素的可选属性的规则。考虑以下元素定义:

<xs:complexType name="sampleElement">
  <xs:attribute name="name" type="xs:string" use="required"/>
  <xs:attribute name="description" type="xs:string" use="optional"/>
  <xs:attribute name="optPrimary" type="xs:string" use="optional"/>
  <xs:attribute name="optSecondary" type="xs:string" use="optional"/>
</xs:complexType


XSD1.1支持这一点。这是一种表达方式:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" xmlns="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xerces="http://xerces.apache.org">
    <xsd:element name="sampleElement">
        <xsd:complexType>
            <xsd:attribute name="name" type="xsd:string" use="required"/>
            <xsd:attribute name="description" type="xsd:string" use="optional"/>
            <xsd:attribute name="optPrimary" type="xsd:string" use="optional"/>
            <xsd:attribute name="optSecondary" type="xsd:string" use="optional"/>
            <xsd:assert test="@optPrimary or not(@optSecondary)" xerces:message="Secondary needs primary..."/>
        </xsd:complexType>          
    </xsd:element>
</xsd:schema> 

XML架构不支持在元素之间创建约束。您已经正确识别了解决此差距的schematron。