XML

XML

Extensible Markup Language, shortened as XML, is a markup language for encoding documents in a machine-readable format. While XML focuses on documents, it found more widespread use in data serialization for storage and transmission. It was soon overtaken in popularity by JSON due to the latter's better interoperability with JavaScript.

Hundreds of other document formats, including HTML (for rendering web pages) and SVG (for rendering scalable graphics), take inspiration from the XML syntax.

How is data encoded in XML?

XML documents consist of content surrounded by markup, generally in the form of tags.

  • Tag: constructs that begin with < and end with >. They can be opening tags <...> or closing tags </...>. Some tags are self-closing <.../>.
  • Attributes: key-value pairs that supplement tags. They are placed within the opening tag and use = as the separator.
  • Content: any text that is not markup and is used to refer to its literal value. Content generally occurs in attribute values or within the opening and closing tag.
  • Element: a logical block in XML. An element could consist of content between an opening and closing tag or just a self-closing tag.

XML can describe nested, and complex data structures since elements can contain other elements in the content portion. XML shines where predefined schemas, data types, and namespaces allow for a very standardized form of data transmission.

What are the shortcomings of XML?

One of the main shortcomings of XML is that it is exceedingly verbose and very redundant. JSON and YAML are much simpler alternatives.

Example

 
<root>
  <org>
    <login>deepsourcelabs</login>
    <name>DeepSource</name>
  </org>
  <repo activelyMaintained="true">
    <name>good-first-issue</name>
    <stats>
      <stat type="stars">400</stat>
      <stat type="forks">130</stat>
    </stats>
  </repo>
</root>

Write clean and secure code with DeepSource

Powerful static analysis that takes 5 minutes to set up and helps you fix code health and security problems on every pull request.