XML 元素与 DTD 不匹配
XML Element is not matching the DTD
考虑以下片段 -
DTD
<!DOCTYPE hotels_list [
<!ELEMENT hotels_list ( hotel+ ) >
<!ELEMENT hotel ( id, name, stars, Facilities, Address, distance_from_center, available ) >
<!ELEMENT id ( #PCDATA ) >
<!ELEMENT name ( #PCDATA ) >
<!ELEMENT stars ( #PCDATA ) >
<!ELEMENT Address ( #PCDATA ) >
<!-- Facilities only contains at least one of the options in (internet,gym,restaurant,parking,pickup -->
<!ELEMENT Facilities (Internet*,Gym*,Restaurant*,Parking*,Pickup*) >
<!ELEMENT available ( #PCDATA ) >
<!ELEMENT distance_from_center ( #PCDATA ) >
]>
XML Code
<hotels_list>
<hotel>
<id>1</id>
<name>Les Jardins Du Marais</name>
<stars>3</stars>
<Facilities>Internet</Facilities>
<Address>74 rue Amelot, Paris, 75011</Address>
<distance_from_center>2</distance_from_center>
<available>True</available>
</hotel>
<hotel>
<id>2</id>
<name>Golden Tulip Little Palace</name>
<stars>4</stars>
<Facilities>Internet,Gym,Parking,Restaurant</Facilities>
<Address>4 rue Salomon
De Caus, Paris 75003</Address>
<distance_from_center>0.1</distance_from_center>
<available>False</available>
</hotel>
</hotels_list>
但是设施显示错误为
The content of element type "Facilities" must match "(Internet*,Gym*,Restaurant*,Parking*,Pickup*)".xml(MSG_CONTENT_INVALID)
我是不是遗漏了什么,有人可以帮忙吗?
感谢您的帮助。
Facilities
是元素列表,不是文本内容的正则表达式。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hotels_list [
<!ELEMENT hotels_list (hotel+)>
<!ELEMENT hotel (id, name, stars, Facilities, Address, distance_from_center, available)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT stars (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!-- Facilities only contains at least one of the options in (internet,gym,restaurant,parking,pickup -->
<!ELEMENT Facilities (Internet*, Gym*, Restaurant*, Parking*, Pickup*)>
<!ELEMENT Internet (#PCDATA)>
<!ELEMENT Gym (#PCDATA)>
<!ELEMENT Restaurant (#PCDATA)>
<!ELEMENT Parking (#PCDATA)>
<!ELEMENT Pickup (#PCDATA)>
<!ELEMENT available (#PCDATA)>
<!ELEMENT distance_from_center (#PCDATA)>
]>
<hotels_list>
<hotel>
<id>1</id>
<name>Les Jardins Du Marais</name>
<stars>3</stars>
<Facilities><Internet/></Facilities>
<Address>74 rue Amelot, Paris, 75011</Address>
<distance_from_center>2</distance_from_center>
<available>True</available>
</hotel>
<hotel>
<id>2</id>
<name>Golden Tulip Little Palace</name>
<stars>4</stars>
<Facilities><Internet/><Gym/><Restaurant/><Parking/></Facilities>
<Address>4 rue Salomon
De Caus, Paris 75003</Address>
<distance_from_center>0.1</distance_from_center>
<available>False</available>
</hotel>
</hotels_list>
考虑以下片段 -
DTD
<!DOCTYPE hotels_list [
<!ELEMENT hotels_list ( hotel+ ) >
<!ELEMENT hotel ( id, name, stars, Facilities, Address, distance_from_center, available ) >
<!ELEMENT id ( #PCDATA ) >
<!ELEMENT name ( #PCDATA ) >
<!ELEMENT stars ( #PCDATA ) >
<!ELEMENT Address ( #PCDATA ) >
<!-- Facilities only contains at least one of the options in (internet,gym,restaurant,parking,pickup -->
<!ELEMENT Facilities (Internet*,Gym*,Restaurant*,Parking*,Pickup*) >
<!ELEMENT available ( #PCDATA ) >
<!ELEMENT distance_from_center ( #PCDATA ) >
]>
XML Code
<hotels_list>
<hotel>
<id>1</id>
<name>Les Jardins Du Marais</name>
<stars>3</stars>
<Facilities>Internet</Facilities>
<Address>74 rue Amelot, Paris, 75011</Address>
<distance_from_center>2</distance_from_center>
<available>True</available>
</hotel>
<hotel>
<id>2</id>
<name>Golden Tulip Little Palace</name>
<stars>4</stars>
<Facilities>Internet,Gym,Parking,Restaurant</Facilities>
<Address>4 rue Salomon
De Caus, Paris 75003</Address>
<distance_from_center>0.1</distance_from_center>
<available>False</available>
</hotel>
</hotels_list>
但是设施显示错误为
The content of element type "Facilities" must match "(Internet*,Gym*,Restaurant*,Parking*,Pickup*)".xml(MSG_CONTENT_INVALID)
我是不是遗漏了什么,有人可以帮忙吗?
感谢您的帮助。
Facilities
是元素列表,不是文本内容的正则表达式。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hotels_list [
<!ELEMENT hotels_list (hotel+)>
<!ELEMENT hotel (id, name, stars, Facilities, Address, distance_from_center, available)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT stars (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!-- Facilities only contains at least one of the options in (internet,gym,restaurant,parking,pickup -->
<!ELEMENT Facilities (Internet*, Gym*, Restaurant*, Parking*, Pickup*)>
<!ELEMENT Internet (#PCDATA)>
<!ELEMENT Gym (#PCDATA)>
<!ELEMENT Restaurant (#PCDATA)>
<!ELEMENT Parking (#PCDATA)>
<!ELEMENT Pickup (#PCDATA)>
<!ELEMENT available (#PCDATA)>
<!ELEMENT distance_from_center (#PCDATA)>
]>
<hotels_list>
<hotel>
<id>1</id>
<name>Les Jardins Du Marais</name>
<stars>3</stars>
<Facilities><Internet/></Facilities>
<Address>74 rue Amelot, Paris, 75011</Address>
<distance_from_center>2</distance_from_center>
<available>True</available>
</hotel>
<hotel>
<id>2</id>
<name>Golden Tulip Little Palace</name>
<stars>4</stars>
<Facilities><Internet/><Gym/><Restaurant/><Parking/></Facilities>
<Address>4 rue Salomon
De Caus, Paris 75003</Address>
<distance_from_center>0.1</distance_from_center>
<available>False</available>
</hotel>
</hotels_list>