Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

DTD

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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"
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic