This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Product and Other Certifications and the fly likes DTD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "DTD" Watch "DTD" New topic
Author

DTD

Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
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
Shashank Tanksali
Ranch Hand

Joined: Feb 21, 2001
Posts: 122
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:tanksali@hotmail.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>
Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
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
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
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.
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
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"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DTD
 
Similar Threads
Wrong answer?
passed
ANY, anyType, &lt;xsd:any&gt;
XML One liners for the exam....
How to delete empty tag from XML