Is there a difference between 'valid xml' and 'well formed xml'?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

There is a difference, yes. Xml that adheres to the xml standard is considered well formed, while xml that adheres to a DTD is considered valid.

Up vote 17 down vote favorite 1 share g+ share fb share tw.

I wasnt aware of a difference, but a coworker says there is, although he can't back it up. What's the difference if any? Xml validation xml-schema dtd link|improve this question edited Jan 27 '09 at 5:56Eddie17.6k43172 asked Sep 25 '08 at 16:53user189311,26831218 88% accept rate.

3 Or an XML Schema, or RelaxNG, or Schematron, for that matter. – Torsten Marek Sep 25 '08 at 17:09 3 Probably worth pointing out that well-formedness is a prerequisite for validity. – Quentin Jun 7 '10 at 11:20 @David: Excellent point!

– Kilhoffer Jun 8 '10 at 16:48.

Valid XML is XML that succeeds validation against a DTD. Well formed XML is XML that has all tags closed in the proper order and, if it has a declaration, it has it first thing in the file with the proper attributes. In other words, validity refers to semantics, well-formedness refers to syntax.

So you can have invalid well formed XML.

As others have said, well-formed XML conforms to the XML spec, and valid XML conforms to a given schema. Another way to put it is that well-formed XML is syntactically correct (it can be parsed), while valid XML is semantically correct (it can be matched to a known vocabulary and grammar). An XML document cannot be valid until it is well-formed.

All XML documents are held to the same standard for well-formedness (an RFC put out by the W3). One XML document can be valid against some schemas, and invalid against others. There are a number of schema languages, many of which are themselves XML-based.

Well-Formed XML is XML that meets the syntactic requirements of the language. Not missing any closing tags, having all your singleton tags use instead of just , and having your closing tags in the right order. Valid XML is XML that uses a DTD and complies with all its requirements.

So if you use an attribute improperly, you violate the DTD and aren't valid. All valid XML is well-formed, but not all well-formed XML is valid.

XML is well-formed if meets the requirements for all XML documents set out by the standards - so things like having a single root node, having nodes correctly nested, all nodes having a closing tag (or using the empty node shorthand of a slash before the closing angle bracket), attributes being quoted etc. Being well-formed just means it adheres to the rules of XML and can therefore be parsed properly. XML is valid if it will validate against a DTD or schema. This obviously differs from case to case - XML that is valid against one schema won't be valid against another schema, even though it is still well-formed.

If XML isn't well-formed it can't be properly parsed - parsers will simply throw an exception or report an error. This is generic and it doesn't matter what your XML contains. Only once it is parsed can it be checked for validity.

This domain or context dependent and requires a DTD or schema to validate against. For simple XML documents, you may not have a DTD or schema, in which case you can't know if the XML is valid - the concept or validity simply doesn't apply in this case. Of course, this doesn't mean you can't use it, it just means you can't tell whether or not it's valid.

I'll add that valid XML also implies that it's well-formed, but well-formed XML is not necessarily valid.

In addition to the aforementioned DTD's, there are 2 other ways of describing and validating XML documents are XMLSchema and RelaxNG, both of which may be easier to use and support more features than DTD.

W3C, in the XML specification, has defined certain rules that needs to be followed while creating XML documents. The examples of such rules include having exactly one root element, having end-tag for each start-tag, using single/double quotes for attribute values, and so on. If an XML document follows all these rules, it is said to be well-formed document and XML parsers can be used to parse and process such documents.

Document Type Definitions (DTDs) or XML Schemas can be used to define the structure and content of a specific class of XML documents. This includes the parent-child relationship details, attribute lists, data type information, value restrictions, etc. In addition to the well-formedness rules, if an XML document also follows the rules specified in the associated DTD/Schema, it is said to be a valid XML document. All valid XML documents are well-formed, but the reverse is not always true.

Well-formed XML documents do not necessarily have to be valid.

Well, XML that isn't well formed, sort of by definition, isn't XML. Poeple usually refer to valid XML as XML that adheres to a certian scheama (XSD or DTD).

This answer is fuzzy but correct. – bortzmeyer Jan 27 '09 at 12:30.

If XML is confirming to DTD rules then it's a valid XML. If a XML document is conforming to XML rules (all tags started are closed,there is a root element etc)then it's a well formed XML.

DTD is the acronym for Document Type Definition. This is a description of the content for a family of XML files. This is part of the XML 1.0 specification, and allows one to describe and verify that a given document instance conforms to the set of rules detailing its structure and content.

Validation is the process of checking a document against a DTD (more generally against a set of construction rules). The validation process and building DTDs are the two most difficult parts of the XML life cycle. Briefly a DTD defines all the possible elements to be found within your document, what is the formal shape of your document tree (by defining the allowed content of an element; either text, a regular expression for the allowed list of children, or mixed content i.e.

Both text and children). The DTD also defines the valid attributes for all elements and the types of those attributes.

Yes this is absolutly fine and corrrect – Rachna Garg Jan 27 '11 at 9:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions