0

Впервые столкнулся с XML, составил схему и при попытке проверить ее через онлайн-переводчики выдает ошибку, никак не могу разобраться что ему не нравится. (Element http://www.w3.org/2001/XMLSchema:simpleType is invalid in this context.)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="A" type="Home"/>

<xs:complexType name="Home">
     <xs:sequence>
        <xs:element name="B" type="letter" maxOccurs="5" minOccurs="0"/>        
        <xs:element name="D" type="letter" maxOccurs="2" minOccurs="0"/>         
     </xs:sequence>          
</xs:complexType>

<xs:complexType name="letter">
    <xs:sequence>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:pattern value="[A-Fa-f]{1}"/>
            </xs:restriction> 
        </xs:simpleType>
    </xs:sequence>
    <xs:attribute name="C" type="Ctype" use="required"/>         
</xs:complexType>

<xs:simpleType name="Ctype">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{4}"/>
    </xs:restriction>
</xs:simpleType>
</xs:schema>

Прошу помощи в указании в чем ошибка и желательно как ее исправить, или хотя бы подсказки в нужном направлении. По заданию схему необходимо составить по имеющемуся xml.

<A>
<B C="1234">d</B>
<B C="4211">b</B>
<B C="0312">b</B>
<B C="1543">d</B>
<B C="2345">b</B>
<D C="1233">d</D>
<D C="4321">b</D>
</A>

Заранее благодарю за помощь.

1 ответ 1

0

Эта схема в точности валидирует ваш xml.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="A" type="Home"/>

  <xs:complexType name="Home">
    <xs:sequence>
      <xs:element name="B" type="letter" maxOccurs="5" minOccurs="0"/>
      <xs:element name="D" type="letter" maxOccurs="2" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="letter">
    <xs:simpleContent>
      <xs:extension base="letterType">
        <xs:attribute name="C" type="Ctype" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="letterType">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Fa-f]{1}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="Ctype">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{4}"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.