Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这是xml模式的好语法吗?_Xml_Xsd_Computer Science_Grammar - Fatal编程技术网

这是xml模式的好语法吗?

这是xml模式的好语法吗?,xml,xsd,computer-science,grammar,Xml,Xsd,Computer Science,Grammar,如果我有这些规则: PIZZA-->doughSAUCECHEESE SAUCE-->marinara | bbq | pesto CHEESE-->mozarella | 比萨饼串由字面上的“面团”和三种酱汁中的一种组成。它可能在那里结束(没有奶酪),或者以字面上的“莫扎雷拉”结尾。 以下是我的xml模式: <xs:element name="pizza"> <xs:complexType> <xs:element name=

如果我有这些规则:

PIZZA-->doughSAUCECHEESE

SAUCE-->marinara | bbq | pesto

CHEESE-->mozarella | 
比萨饼串由字面上的“面团”和三种酱汁中的一种组成。它可能在那里结束(没有奶酪),或者以字面上的“莫扎雷拉”结尾。 以下是我的xml模式:

<xs:element name="pizza">
  <xs:complexType>
    <xs:element name="doughLiteral" type="xs:string" fixed="dough"/>
    <xs:element name="sauce">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="marinara"/>
          <xs:enumeration value="bbq"/>
          <xs:enumeration value="pesto"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
    <xs:element name="cheese">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="mozarella"/>
        </xs:restriction>
      </xs:simpleType>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value=""/>
        </xs:restriction> 
      </xs:simpleType>
    </xs:element>
  </xs: complexType>
</xs: element>


我不确定是否正确指定了空字符串。另外,我读到属性在默认情况下是可选的,元素在默认情况下是必需的,尽管正确,也就是说,上面的模式声明必须有1个元素,对吗?谢谢。

元素在默认情况下是必需的,要使它们成为可选的,请使用
minOccurs=“0”

缺少
xs:sequence
,并且
cheese
元素定义中使用的双
xs:simpleType
不正确

正确的模式应如下所示:

<xs:element name="pizza">
  <xs:complexType>
    <xs:sequence>
    <xs:element name="doughLiteral" type="xs:string" fixed="dough"/>
    <xs:element name="sauce">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="marinara"/>
          <xs:enumeration value="bbq"/>
          <xs:enumeration value="pesto"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
    <xs:element name="cheese" minOccurs="0">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="mozarella"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

话虽如此,正如@seki正确指出的,该模式定义了如下XML结构:

<pizza>
  <doughLiteral>dough</doughLiteral>
  <sauce>marinara</sauce>
  <cheese>mozzarella</cheese>
</pizza>

面团
玛丽娜拉
莫泽雷勒干酪

不是您在问题开头指定的纯文本语法。

我无法确定您定义的语法与xml之间的关系