为什么这个DTD无效?

时间:2020-12-18 16:31:38

I've tried validating this DTD using 1-2 validators, however I'm unsure on why it is not valid:

我已经尝试使用1-2个验证器验证此DTD,但是我不确定它为什么无效:

DTD code:

Any help will be appreciated!

任何帮助将不胜感激!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cars 
[
    <!ELEMENT car (maker, model, year, colour, engine, number_of_doors, accessories)>

    <!ELEMENT maker (#PCDATA)>
    <!ELEMENT model (#PCDATA)>
    <!ELEMENT year (#PCDATA)>
    <!ELEMENT colour (#PCDATA)>
    <!ELEMENT engine (number_of_cylinders)>
    <!ELEMENT number_of_doors (#PCDATA)>
    <!ELEMENT accessories (#PCDATA)>

    <!ELEMENT number_of_cylinders (#PCDATA)>

    <!ATTLIST accessories radio (yes|no) #REQUIRED
        air_conditioning (yes|no) #REQUIRED
        power_windows (yes|no) #REQUIRED
        power_steering (yes|no) #REQUIRED
        power_brakes (yes|no) #REQUIRED
    >
]>

2 个解决方案

#1


0  

To make your XML document with an internal DTD subset be valid, make the following changes:

要使具有内部DTD子集的XML文档有效,请进行以下更改:

  1. Change the document element from cars to car.
  2. 将文档元素从汽车更改为汽车。

  3. Build out the XML associated with the given internal subset.

    构建与给定内部子集关联的XML。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE car 
    [
    <!ELEMENT car (maker, model, year, colour, engine, number_of_doors, accessories)>
    
    <!ELEMENT maker (#PCDATA)>
    <!ELEMENT model (#PCDATA)>
    <!ELEMENT year (#PCDATA)>
    <!ELEMENT colour (#PCDATA)>
    <!ELEMENT engine (number_of_cylinders)>
    <!ELEMENT number_of_doors (#PCDATA)>
    <!ELEMENT accessories (#PCDATA)>
    
    <!ELEMENT number_of_cylinders (#PCDATA)>
    
    <!ATTLIST accessories radio (yes|no) #REQUIRED
        air_conditioning (yes|no) #REQUIRED
        power_windows (yes|no) #REQUIRED
        power_steering (yes|no) #REQUIRED
        power_brakes (yes|no) #REQUIRED>
    ]>
    <car>
        <!-- Finish building out the XML per the internal subset. -->
    </car>
    

#2


0  

You can use this validator is the best for DTD https://validator.w3.org/check

您可以使用此验证器最适合DTD https://validator.w3.org/check

#1


0  

To make your XML document with an internal DTD subset be valid, make the following changes:

要使具有内部DTD子集的XML文档有效,请进行以下更改:

  1. Change the document element from cars to car.
  2. 将文档元素从汽车更改为汽车。

  3. Build out the XML associated with the given internal subset.

    构建与给定内部子集关联的XML。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE car 
    [
    <!ELEMENT car (maker, model, year, colour, engine, number_of_doors, accessories)>
    
    <!ELEMENT maker (#PCDATA)>
    <!ELEMENT model (#PCDATA)>
    <!ELEMENT year (#PCDATA)>
    <!ELEMENT colour (#PCDATA)>
    <!ELEMENT engine (number_of_cylinders)>
    <!ELEMENT number_of_doors (#PCDATA)>
    <!ELEMENT accessories (#PCDATA)>
    
    <!ELEMENT number_of_cylinders (#PCDATA)>
    
    <!ATTLIST accessories radio (yes|no) #REQUIRED
        air_conditioning (yes|no) #REQUIRED
        power_windows (yes|no) #REQUIRED
        power_steering (yes|no) #REQUIRED
        power_brakes (yes|no) #REQUIRED>
    ]>
    <car>
        <!-- Finish building out the XML per the internal subset. -->
    </car>
    

#2


0  

You can use this validator is the best for DTD https://validator.w3.org/check

您可以使用此验证器最适合DTD https://validator.w3.org/check