XML不会使用xml中的两(2)个表进行验证 - 两个XML合二为一?

时间:2012-04-13 16:34:05

标签: xml validation dtd xml-dtd

给出下一个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

知道这意味着什么吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

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