Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Learning

 
MONZY THARIAN
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Is it necessary to define the structure of XML using DTD or Schema.?
Since IE can parse XML docment and gives error if it is malformed xml ? then why is the need to define DTD.
Can anyone pls clarify.
Thanks and Regards
Monzy
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An XML document may be malformed in more than one way... IE can recognize for example missing closing tags, special characters in wrong places, and other trivial stuff like that. These validations are based on the XML specification(s) only.
The DTD and schema validation comes into the picture when you want to validate the application specific structure of an XML document. For example, you want your orders.xml to have a root element called "orders" having any number of child elements called "order". IE wouldn't be able to validate this based on the XML specification. That's why you tell the parser what it should validate against using a DTD or an XML schema document.
 
MONZY THARIAN
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Lasse.

The DTD OR SCHEMA file will be stored on the Web Server . Am i right ?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can refer to either a "public" or a "system local" DTD document with the DOCTYPE declaration. Similarly, you can refer to a local or remote schema document.
 
MONZY THARIAN
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse ,
Why do i need to use public DTD document since my xml specification will be unique to my application. ?
How will i know which public DTD to use ?
Does it mean that i do have to create any DTD files i can use some public DTD file.
Pls clarify.

Regards
Monzy
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do i need to use public DTD document since my xml specification will be unique to my application. ?
How will i know which public DTD to use ?
Does it mean that i do have to create any DTD files i can use some public DTD file.

You don't need to use a public DTD document. You don't need to use a local DTD document either. If you don't need validation, you can choose not to use a DTD/schema document at all!
With a public DTD I didn't mean a "standard" DTD like the ones published by W3C, Sun, etc. A public DTD document means that the document is available on a web server somewhere--perhaps on your website, perhaps on someone elses. A local DTD document means that it's located in the same filesystem as the XML document the parser is reading.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic