0

给定下一个 XML 代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hotels SYSTEM "travel.dtd">
<hotels>
    <general>
        <city>MoscowCity</city>
        <address>Sherman23</address>
        <phone>423423432423</phone>
        <hotelDetails>
            <hotel_code>1</hotel_code>
            <hotel_rank>3</hotel_rank>
            <hotel_name>Jacky</hotel_name>
        </hotelDetails>
    </general>
</hotels>

<!DOCTYPE guests SYSTEM "travel.dtd">   // HERE Validation problem 
<guests>
    <guest>
            <id>00000001-0</id>
            <guestDetails>
                <name>Jones</name>
                <city>SomewhereOnlyWeKnow</city>
                <address>NiceStreet</address>
                <state>NiceState</state>
            </guestDetails>
    </guest>
</guests>

及其 DTD 文件:

<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT hotels (general+)>
<!ELEMENT general (city, address, phone, hotelDetails)>
<!ELEMENT hotelDetails (hotel_code, hotel_rank, hotel_name)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT hotel_rank (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT hotel_code (#PCDATA)>
<!ELEMENT hotel_name (#PCDATA)>
<!ELEMENT guests (guest+)>
<!ELEMENT guest (id, guestDetails)>
<!ELEMENT guestDetails (name, city, address, state)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT state (#PCDATA)>

该文件不会得到验证,并且 XMLspy 输出是:

 Character 'D' is grammatically unexpected

知道这意味着什么吗?

谢谢!

4

1 回答 1

1

我认为您不能在一个 XML 文档中拥有两个根元素。据我所知,这意味着您的 XML 格式不正确,因此在第一个根元素的结束标记之后出现错误消息。

于 2012-04-13T16:40:36.690 回答