-1

Okay so I have been tooling around with this for hours and I still can't seem to figure out what the problem is, but this is what I have so far. This is from the site that the instructor gave us to validate our xml, and from the validating service on W3 Schools I was given no errors using the exact xml below. My question is what is causing the two different results and what can I do to make the other validation service accept my code. Thanks for any help.

Also, this is the site that I'm getting the errors from(and the one the instructor is requiring a screen shot of that says the code is valid) http://www.xmlvalidation.com/

16: 10  Document root element "listing", must match DOCTYPE root "tv".
47: 11  The content of element type "listing" must match "(mfr,type,size,hdmi)".



<?xml version="1.0" encoding="UTF-8" ?>
<!--DOCTYPE tv SYSTEM "TVs2.dtd"-->
<!DOCTYPE tv [
   <!ELEMENT listing (mfr,type,size,hdmi)>
   <!ELEMENT tv (mfr,type,size,hdmi)+>
   <!ELEMENT mfr (#PCDATA)>
   <!ELEMENT type (#PCDATA)>
   <!ELEMENT size (#PCDATA)>
   <!ELEMENT hdmi (#PCDATA)>

   <!ATTLIST tv class CDATA #REQUIRED>
   <!ATTLIST tv condition CDATA #REQUIRED>
]>

<?xml-stylesheet type="text/css" href="TVs.css"?>
<listing>
    <tv class="TV" condition="new">
        <mfr>Sony</mfr>
        <type>LCD</type>
        <size>40" (39.5" diagonal)</size>
        <hdmi>4 ports</hdmi>    
    </tv>
    <tv class="TV" condition="new">
        <mfr>Samsung</mfr>
        <type>LED</type>
        <size>32"</size>
        <hdmi>3 ports</hdmi>    
    </tv>
    <tv class="Monitor" condition="used">
        <mfr>Hitachi</mfr>
        <type>PLASMA</type>
        <size>60"</size>
        <hdmi>2 ports</hdmi>        
    </tv>
    <tv class="Monitor" condition="used">
        <mfr>Toshiba</mfr>
        <type>LED</type>
        <size>75"</size>
        <hdmi>3 ports</hdmi>            
    </tv>
    <tv class="TV" condition="new">
        <mfr>LG</mfr>
        <type>LCD</type>
        <size>32"</size>
        <hdmi>3 ports</hdmi>            
    </tv>
</listing>
John Joseph
  • 189
  • 2
  • 3
  • 14

3 Answers3

1

what is causing the two different results

Probably, W3Schools (who are, in general, awful) isn't providing proper DTD validation… but you didn't point to a specific service or program there so it is hard to say.

and what can I do to make the other validation service accept my code

Fix the errors. They are in relatively plain english.


The name of the root element (<listing>) needs to match the word immediately after DOCTYPE in the Doctype, just as the error message says.

So either rename the root element to tv or change the word immediately after DOCTYPE to listing.


<listing> is allowed to contain mfr, type, size, and hdmi elements, but you've put tv elements there.

Change what it is allowed to contain or change what you are putting there.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • What you're suggesting I have done in different ways the whole time I've been working on this (since 7am my time). For whatever reason the validation service THIS SITE THAT WAS IN MY POST (http://www.xmlvalidation.com/) gives either the errors that I included or this one (47:11 The content of element type "listing" must match "(tv,mfr,type,size,hdmi)".). I have put a lot of time into this and that's the reason I'm asking here not to have someone do it for me. – John Joseph Nov 01 '14 at 23:31
  • @JohnDziendziel — The code you have provided in your question is wrong and should generate those errors. If you have fixed them and are still getting the errors, then you should update the question to include the corrected code. (When I make the changes I mentioned in this answer, xmlvalidation.com/ says it is valid). – Quentin Nov 02 '14 at 00:11
1

You have http://validator.w3.org/#validate_by_input is betther than http://www.xmlvalidation.com/ .

W3C is the official site (is the main international standards organization for the World Wide Web), and your validator is best.

Is a note.

CodeNoob
  • 345
  • 4
  • 17
0

Below is the corrected dtd code, here's what I found in my listing declaration I needed to add tv+ to show that the element was going to occur more than one time and that is what I was missing.

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE listing [
   <!ELEMENT listing (tv+)>
   <!ELEMENT tv (mfr,type,size,hdmi)>
   <!ELEMENT mfr (#PCDATA)>
   <!ELEMENT type (#PCDATA)>
   <!ELEMENT size (#PCDATA)>
   <!ELEMENT hdmi (#PCDATA)>

   <!ATTLIST tv class CDATA #REQUIRED>
   <!ATTLIST tv condition CDATA #REQUIRED>
]>

<?xml-stylesheet type="text/css" href="TVs.css"?>
<listing>
    <tv class="TV" condition="new">
        <mfr>Sony</mfr>
        <type>LCD</type>
        <size>40" (39.5" diagonal)</size>
        <hdmi>4 ports</hdmi>    
    </tv>
...
</listing>
John Joseph
  • 189
  • 2
  • 3
  • 14