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
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 ]
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
IBM Certified Developer -XML and Related Technologies(141)<br />SCJP2 SCWCD
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!
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.
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.