Перечисление атрибутов XML Схема - PullRequest
0 голосов
/ 07 апреля 2020

Попытка завершить схему XML, которая включает родительский элемент car, который имеет дочерние элементы make, model и т.д. c. Элемент accessories нуждается в атрибутах, которые имеют только значения yes или no. Я работал над этим некоторое время сейчас и добрался до ниже, но это не дает ошибку, просто красный крестик в строке 22 (расширение базы = "cxml: Да Нет"). В строке XML я получаю следующую ошибку в строке 15 В этой строке найдено несколько аннотаций:

    - cvc-complex-type.4: Attribute 'Radio' must appear on element 'cxml:Accessories'.
    - cvc-complex-type.4: Attribute 'Air_Conditioning' must appear on element 
     'cxml:Accessories'.
    - cvc-complex-type.4: Attribute 'Power_Steering' must appear on element 
     'cxml:Accessories'.
    - cvc-complex-type.4: Attribute 'Power_Brakes' must appear on element 
     'cxml:Accessories'.
    - cvc-complex-type.4: Attribute 'Power_Windows' must appear on element 
     'cxml:Accessories'. I am using eclipse.

Я знаю, что аксессуары являются причиной проблемы, но я не могу найти решение. Любая помощь будет оценена.

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://xxxxxxxxxx.com/CarsXML" 
xmlns:cxml="http://xxxxxxxxxxxx.com/CarsXML" elementFormDefault="qualified" > 



<xs:element name= "Car">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Make" type="xs:string" />
            <xs:element name="Model" type="xs:string" />
            <xs:element name="Year" type="xs:gYear" />
            <xs:element name="Color" type="xs:string" />
            <xs:element name="Engine" type="cxml:EngineInfo" />
            <xs:element name="Number_of_Doors" type="xs:positiveInteger" />
            <xs:element name="Transmission_Type" type="cxml:TransInfo" />
            <xs:element name="Accessories" >
                <xs:complexType>
                <xs:simpleContent>
                    <extension base="cxml:YesNo">
                    <xs:attribute name="Radio"  type="cxml:YesNo" use="required" />
                    <xs:attribute name="Air_Conditioning" type="cxml:YesNo" use="required"/>
                    <xs:attribute name="Power_Windows" type="cxml:YesNo" use="required"/>
                    <xs:attribute name="Power_Steering" type="cxml:YesNo" use="required"/>
                    <xs:attribute name="Power_Brakes" type="cxml:YesNo" use="required"/>
                    </extension>
                </xs:simpleContent>
                </xs:complexType>
            </xs:element>   
        </xs:sequence>
    </xs:complexType>
</xs:element>

    <xs:complexType name="EngineInfo">
        <xs:sequence>
            <xs:element name="Number_Of_Cylinders" type="xs:positiveInteger"></xs:element>
            <xs:element name="Fuel_System">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                    <xs:enumeration value="Carbureted"/>
                    <xs:enumeration value="Fuel_Injected"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

     <xs:complexType name="TransInfo">
        <xs:sequence>
            <xs:element name="Transmission_Type">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                    <xs:enumeration value="Automatic"/>
                    <xs:enumeration value="Manual"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:simpleType name="YesNo">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Yes" />
      <xs:enumeration value="No" />
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<cxml:Car xmlns:cxml="http://cis337-0217.cisdprogram.com/CarsXML" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:xxxxxxxx.com/CarsXML 
Cars.xsd ">
  <cxml:Make>cxml:Make</cxml:Make>
  <cxml:Model>cxml:Model</cxml:Model>
  <cxml:Year>2001</cxml:Year>
  <cxml:Color>cxml:Color</cxml:Color>
  <cxml:Engine>
    <cxml:Number_Of_Cylinders>1</cxml:Number_Of_Cylinders>
    <cxml:Fuel_System>Carbureted</cxml:Fuel_System>
  </cxml:Engine>
  <cxml:Number_of_Doors>1</cxml:Number_of_Doors>
  <cxml:Transmission_Type>
    <cxml:Transmission_Type>Automatic</cxml:Transmission_Type>
  </cxml:Transmission_Type>
  <cxml:Accessories>cxml:Accessories</cxml:Accessories>
</cxml:Car>

1 Ответ

0 голосов
/ 07 апреля 2020

Используйте <xs:extension> вместо <extension>.

...