我已尝试使用1-2个验证器来验证此DTD,但我不确定它为何无效:
DTD代码:
任何帮助将不胜感激!
<?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
>
]>
答案 0 :(得分:0)
要使具有内部DTD子集的XML文档有效,请进行以下更改:
cars
更改为car
。构建与给定内部子集关联的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>
答案 1 :(得分:0)
您可以使用此验证器最适合DTD https://validator.w3.org/check