DEV Community

Quinn Lashinsky
Quinn Lashinsky

Posted on • Originally published at Medium

XML

Originally published on Medium - 02-28-2019

What is XML? Why do we use it?

Extensible Markup Language (XML) is an all-purpose tool for creating your own markup language. By defining a set of rules, and giving your language an applicable style sheet, you can define your own markup that is specialized to your business, or application needs. While most of us are familiar with HTML, XML differs in that it allows you to build a markup language. XML is pervasive, with applications in business, banking, and healthcare industries. As a non-proprietary open source language, XML combines the ability to be used as a powerful form of data transfer with flexibility and ease of use.

Most of us are familiar with HTML and its applications, but how do the two differ?

HTML and XML are both children of their parent language SGML

They’re CHILDREN. Get it?!

Where SGML is robust but complex, and HTML is inflexible in its already defined structure, XML bridges the gap combining elements from both to create a responsive and flexible way to structure data. Users cannot create new tags or define how they should be displayed in the browser in HTML, while they can in SGML or XML. XML is able to explicitly define new tags, and provide a middle-ground between HTML and SGML documents.

Creating An XML Markup Language — XML Components

Declaration

To create a language first you must create your declaration. Much like the first line in an HTML document, an XML declaration includes information that defines attributes of the document.

You must include a version and encoding, but the standalone declaration is only if you want to ignore the standard rules provided by the DTD (Document Type Definition). The DTD is the group of markup declarations for SGML-family languages.

Tags and Elements

Tags are self-descriptive and define the types of elements that exist within your XML file. Elements in an XML language are the building blocks of the XML file. They contain one root element and may contain nested elements.

Attributes

Attributes provide additional information about elements, they are name-value pairs with single or double quotes. Attribute names must be unique.

Comments

Comments provide additional information about the document but are ultimately not parsed.

Schemas

Schemas describe the structure and content of an XML document. They create a common vocabulary for all documents of a particular XML language. You can create your own schema by using the DTD or creating your own XML schema. WW3 has some resources to get you started!

Advantages and Final Thoughts

XML allows a developer to create their own semantic data structure, set up rules governing the data, and use the data throughout their applications. A markup language that is unique and serves the needs of an application can make code clearer and more explicit. Entire industries have built their own XML languages some of which include EPUB, RSS, SVG, and MathML. XML was even the most popular data interchange format until JSON was established. Give it a try and see if you can build your own language!

Top comments (0)