Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

DTD

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic