---
language: xml
filename: learnxml.xml
contributors:
- ["João Farias", "https://github.com/JoaoGFarias"]
- ["Rachel Stiyer", "https://github.com/rstiyer"]
- ["Deepanshu Utkarsh", "https://github.com/duci9y"]
---
XML is a markup language designed to store and transport data. It is supposed to be both human readable and machine readable.
Unlike HTML, XML does not specify how to display or to format data, it just carries it.
Distinctions are made between the **content** and the **markup**. In short, content could be anything, markup is defined.
## Some definitions and introductions
XML Documents are basically made up of *elements* which can have *attributes* describing them and may contain some textual content or more elements as its children. All XML documents must have a root element, which is the ancestor of all the other elements in the document.
XML Parsers are designed to be very strict, and will stop parsing malformed documents. Therefore it must be ensured that all XML documents follow the [XML Syntax Rules](http://www.w3schools.com/xml/xml_syntax.asp).
```xml
Content
Text
Text
Text
```
## An XML document
This is what makes XML versatile. It is human readable too. The following document tells us that it defines a bookstore which sells three books, one of which is Learning XML by Erik T. Ray. All this without having used an XML Parser yet.
```xml
Everyday Italian
Giada De Laurentiis
2005
30.00
Harry Potter
J K. Rowling
2005
29.99
Learning XML
Erik T. Ray
2003
39.95
```
## Well-formedness and Validation
A XML document is *well-formed* if it is syntactically correct. However, it is possible to add more constraints to the document, using Document Type Definitions (DTDs). A document whose elements are attributes are declared in a DTD and which follows the grammar specified in that DTD is called *valid* with respect to that DTD, in addition to being well-formed.
```xml
Everyday Italian
Giada De Laurentiis
2005
30.00
]>
]>
Everyday Italian
30.00
```
## DTD Compatibility and XML Schema Definitions
Support for DTDs is ubiquitous because they are so old. Unfortunately, modern XML features like namespaces are not supported by DTDs. XML Schema Definitions (XSDs) are meant to replace DTDs for defining XML document grammar.
## Resources
* [Validate your XML](http://www.xmlvalidation.com)
## Further Reading
* [XML Schema Definitions Tutorial](http://www.w3schools.com/schema/)
* [DTD Tutorial](http://www.w3schools.com/xml/xml_dtd_intro.asp)
* [XML Tutorial](http://www.w3schools.com/xml/default.asp)
* [Using XPath queries to parse XML](http://www.w3schools.com/xml/xml_xpath.asp)