xsd:为元素定义两个可能的属性语法?

xsd:为元素定义两个可能的属性语法?,xsd,xsd-validation,complextype,Xsd,Xsd Validation,Complextype,我需要为元素接受2个属性语法: <fsinfo line="70" comment="# a comment" /> <fsinfo line="80" real_dev="/dev/sda2" mount_dev="LABEL=root" mp="/" fs="ext4" options="defaults" dump="1" pass="1" /> 我已经创建了一个能够验证第80行的xsd: <xsd:element name="fsinfo">

我需要为元素接受2个属性语法:

<fsinfo  line="70" comment="# a comment" />
<fsinfo  line="80" real_dev="/dev/sda2" mount_dev="LABEL=root" mp="/"  fs="ext4" options="defaults" dump="1" pass="1" />

我已经创建了一个能够验证第80行的xsd:

<xsd:element name="fsinfo">
    <xsd:complexType>
        <xsd:attribute name="line"/>
        <xsd:attribute name="real_dev" use="required"/>
        <xsd:attribute name="mount_dev"/>
        <xsd:attribute name="mp" use="required"/>
        <xsd:attribute name="fs" use="required"/>
        <xsd:attribute name="mkfs_opts"/>
        <xsd:attribute name="options" default="defaults"/>
        <xsd:attribute name="dump" use="required"/>
        <xsd:attribute name="pass" use="required"/>
        <xsd:attribute name="format"/>
        <xsd:attribute name="comment"/>
    </xsd:complexType>
</xsd:element>

要验证第70行,我可以执行以下操作:

<xsd:element name="fsinfo">
    <xsd:complexType>
        <xsd:attribute name="line"/>
        <xsd:attribute name="comment"/>
    </xsd:complexType>
</xsd:element>

1/如何合并两个语法,以便验证第70行和第80行

2/如何避免空的fsinfo标签

3/“fsinfo”属性可以是任意顺序

重要信息,如果存在多个“line”和“comment”属性(例如“mount_dev”),则必须存在所有相关的必需参数。(第80行验证方案)

注意:我不能更改我的xml文件,因为我必须保持与旧软件的兼容性(我正在添加验证以使其更加健壮)


注2:用于验证的工具:xmlstarlet--err--xsd myxsdfile.xsd myxmlfile.xml

不幸的是,我没有关于是否可以使用xsd 1.1的信息 使用资产有很大的可能性,可以帮助您管理资产

我无法观察完整的xml示例以及xsd,但我可以创建一个示例xsd如何使用断言

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.1">
    <xs:element name="root" type="root"/>
    <xs:complexType name="root">
        <xs:sequence>
            <xs:element name="fsinfo">
                <xs:complexType>
                    <xs:attribute name="line"/>
                    <xs:attribute name="real_dev"/>
                    <xs:attribute name="mount_dev"/>
                    <xs:attribute name="mp"/>
                    <xs:attribute name="fs"/>
                    <xs:attribute name="mkfs_opts"/>
                    <xs:attribute name="options"/>
                    <xs:attribute name="dump"/>
                    <xs:attribute name="pass"/>
                    <xs:attribute name="format"/>
                    <xs:attribute name="comment"/>
                    <xs:assert test="(@line and @comment and not(@real_dev) and not(@mount_dev) and not(@mp) and not(@fs) and not(@mkfs_opts) and not(@dump) and not(@pass) and not(@options) and not(@format)) or ((@line and @real_dev and @mp and @fs and @dump and @pass) and ( @mount_dev or @mkfs_opts or @options or @format or @comment))"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>


感谢您提供的信息,我会尝试一下。我使用的是xmlstarlet-1.6.1。它使用的是libxslt-1.1.28。xsd的完整源代码是要验证的文件示例:感谢您共享您的xsd,因此您可以通过更改您的示例来修改我的代码。我喜欢您的解决方案,但因为我使用xmlstarlet作为使用libxslt的解析器,我不确定是否支持XML 1.1rted。(尤其是我需要支持的redhat-6)