Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DTD and XML

 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i've the following DTD file where the "to" element from within element note is taken off.
<!ELEMENT note(from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
i ve the following xml file:
and this xml file contains an element "to".
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Angel</to>
<from>Helpless</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Now, when i execute this xml file in IE and validate it, the validation goes fine. I don't know why. shouldn't it fail? coz my understanding is that a xml file must contain only elements that are defined in DTD. pls clearify me with it.
here is how i did validation:
right click in IE5 and select "Validate XML" from the pop up menu.
thanks.
himal
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himal,
When I validate this example, I get the error
Element from expected in place of to. You are right when you say the XML file must contain elements in the DTD. What kind of parser are you using?
[ September 13, 2002: Message edited by: Aaron O'Brien ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make sure that it is looking at the appropriate external DTD. There is no way that this can get validated successfully with the dtd given by you here
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
Is it only with schemas that the version of your browser makes a difference? Something tells me this but I am not 100% sure!
Thanks
 
Vasudha Deepak
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The external file that you are referring has a <to> element.Hence it will not flag an error,when you add a <to> element
But I tried to add one more element, <subHeading> to the XML file.
However in IE6 the file still gets validated,but when checked with XML Spy,it pops an error,which means that it is referring to the correct external DTD, and any variation in the XML file,prevents it from getting validated.
So the problem is with IE and not the DTD.
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Angel</to>
<from>Helpless</from>
<hello></hello>
<subHeading>New</subHeading>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Hope this helps.
Vasudha
 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Aron,
i've MSXML4.0 and i am validating my xml from IE5. like i mentioned, right click on IE5 and select "Validate XML" give no error. i am wondering if it's due to IE5.
himal
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that when you right click in your browser,
that the browser itself is a non validating parser. Which means that it is only checking for wellformness and not checking the DTD.
Please someone correct me if I am wrong!
 
Aaron O'Brien
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a DTD with...
<!ELEMENT note(from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Your element declarations can appear in any order
but if they are not in sequence in the context node - note(from, heading, body), the element decalrations do not make a difference in the XML file itself if they are not decalred in the sequence. That is why XML Spy gives an error because it is a Validating parser but the xml file will still show up in the browser because the browser is a non-validating parser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic