0

Given the next XML code :

<?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>

And its DTD file :

<?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)>

The file won't get validated , and XMLspy output is :

 Character 'D' is grammatically unexpected

Any idea what that means ?

Thanks!

JAN
  • 21,236
  • 66
  • 181
  • 318
  • Apparently it means you took two XML files and saved them as one file, resulting in invalid XML, with two root nodes and two doctypes, while only one root node is allowed. – GSerg Apr 13 '12 at 16:40

1 Answers1

1

I don't think you can have two root elements in one XML document. As far as I know this means your XML is not well-formed, hence the error message after the closing tag of the first root element.

  • I'm requested to have only one XML file for both tables, therefore I cannot split them into two separated XMLs. No other way to do that ? thanks – JAN Apr 13 '12 at 16:51
  • 1
    The only way I can think of is to put the two tables inside a new root element, but of course you would have to add that to the DTD to make it a valid XML document. – TrailOfFire Apr 13 '12 at 16:57
  • Okay ,can you please give me an example of explain how to do that ? – JAN Apr 13 '12 at 16:58
  • 1
    Let's say the root element shall be , then you would need to add the line `<!ELEMENT travel (hotels|guests)+>` to the DTD. The XML would look like ` ` – TrailOfFire Apr 13 '12 at 17:04
  • 1
    Forgot the closing tag `` at the end of the example above. – TrailOfFire Apr 13 '12 at 17:15
  • I've made the changes - edited my original post - but the code still won't get validated , can you please give me a feedback ? 10x. – JAN Apr 13 '12 at 17:48
  • 1
    You have to remove the comment tags (``) in your XML. Additionally, the definition for the element is missing in your DTD. Add the line `<!ELEMENT id (#PCDATA)>` to the DTD and it should be fine. – TrailOfFire Apr 13 '12 at 21:17