Hi, I found the following in w3schools.com " Elements with children (sequences) Elements with one or more children are defined with the name of the children elements inside parentheses: <!ELEMENT element-name (child-element-name)> or <!ELEMENT element-name (child-element-name,child-element-name,.....)>example:<!ELEMENT note (to,from,heading,body)> <b>When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document</b>. " But it accepts even when the child elements are not in the order specified in the dtd. So which is correct? Thanks Shoba
Hi Shobha, By default, the validation is turned off in most parsers. So when you use the parser, you need to explicitly turn on the validation. If you are using SAX2Count (Part of xerces distribution which you can download from the Apache web site ) to parse the XML file, then you can turn the validation on by specifying a command line like java sax.SAX2Count -v myxml.xml In case you have your own program to read an XML document, then try // Initialize XMLReader myReader.setFeature("http://xml.org/sax/features/validation",true); In your case, you appear to be using a validating parser, but have not turned the validation on. So it is currently only checking for well formedness. Hope this helps . . . Shashank
<b><br /><a href="http://mailto:email@example.com" target="_blank" rel="nofollow">Shashank Tanksali</a><br /><i><br />SCJP2,SCJD2,SCWCD<br />IBM Certified Developer - XML and Related Technologies<br />PMI Certified Project Management Professional<br /></i><br /></b>
Joined: Mar 29, 2001
Shashank, I was using xml spy and the validation is on. It pointed out someother (validation)mistakes and didn't complaint about the order of the elements. Thanks Shoba
Originally posted by Shoba, Ramachandran: Shashank, I was using xml spy and the validation is on. It pointed out someother (validation)mistakes and didn't complaint about the order of the elements. Thanks Shoba
XML spy would indeed complain if you change the order of the elements, if you do the validation against the DTD. Try it again.
Joined: Oct 29, 2000
if your DTD is defined as <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT message (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
and xml document is defined as <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE message SYSTEM " test.dtd"> <message> <from>sobha</from> <to>hema</to> <heading>hi</heading> <body>hello</body> </message> On validation, XMLSpy will complain saying that, "Mandatory element "to" expected in place of "from"