XML and JSON
How is XML different from HTML?
The eXtensible Markup Language (XML) describes the content in terms of what data is being described rather than how it’s to be displayed. Instead of being locked into standard tags and formats for data, users can build their own markup languages to accommodate particular data formats and needs.
For example, say you want to capture a credit card number.
In HTML, the paragraph tags (
and
) are used to define text and numeric elements. Almost any text or graphic can fall between these tags and be treated as a paragraph. The HTML code could appear as:1234567890123456
The browser will interpret the data contained within the
and
tags as a separate paragraph. However, the paragraph tags tell us nothing about the data contained within them. A better approach lies in creating tags that actually describe the data contained within them. Using XML we could create a “credit card number” tag that’s used exclusively for credit card data:In addition, HTML tags don’t provide any methodology for data validation. If we needed a tag for an age field, we know a person’s age can only be between 0 and 120, but any data may be inserted between
and
tags. How would we know if the age was valid? XML schema diagrams (XSDs) allows you to specify all kinds of data validation for a specific XML tag. An XSD schema definition that restricts age to be in the range 0, 120 would read: