File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XML Learning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Learning" Watch "XML Learning" New topic
Author

XML Learning

MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
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


Think Big . So shall you become big.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
Thanks a lot Lasse.

The DTD OR SCHEMA file will be stored on the Web Server . Am i right ?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Feb 21, 2001
Posts: 63
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Learning