Is XML better than YAML
JSON, XML and YAML in comparison
For Web APIs and configurations, XML is increasingly being replaced by simpler formats such as JSON and YAML. For example, Twitter has discontinued its support for XML in its streaming APIs. This article compares JSON, YAML and XML and shows the strengths of the formats for certain areas of application.
The usual separation of data (e.g. XML documents) and code (e.g. Java) is thus avoided. Even the Lisp language from the pioneering days of EDP made no difference between code and data. The use of JSON for the asynchronous transfer of data between servers and websites is particularly popular. JSON has now almost replaced XML as AJAX format.
For the same order, you will find the corresponding YAML and XML documents in the following sections.
The strengths of JSON lie in a clear notation, low overhead and good support from a large number of programming languages.
YAML is the short form of "YAML Ain't Markup Language". YAML became known as a format for configuring Ruby on Rails. In contrast to XML, the language for data exchange is easy to read and edit. This was achieved by eliminating brackets, quotation marks and tags. YAML uses indentations to represent hierarchical structures. This makes the order in Listing 2 even more compact and clear than the order in JSON format.
In the example we find a list of positions (items). As in word processing, a list is created by placing a bullet in front of it.
Since YAML is a superset of JSON, brackets can optionally be used to achieve JSON compatibility.
YAML is line-oriented and can therefore also be processed by tools such as awk or grep.
In addition, YAML offers some features that cannot be found in JSON and XML. For example, in Listing 3, a Map cities1 defined with capitals. The map cities2 extends the first map to Rome and corrects the entry for Germany.
YAML also supports data types and type casting.
Since the release of the XML 1.0 specification, XML has spread widely. There are thousands of markup languages based on XML. XML has penetrated almost all areas of application. However, there is one area that continues to resist the dominance of XML. Although XML was designed to solve problems in web design, there is a strong dislike for it. For example, Firefox and IE namespace declarations in XML documents simply filter out rather than display them.
Listing 4 shows the order already known from above in XML format.
The order in XML format has a higher overhead and is more confusing than the JSON or YAML document. If we left our comparison at that, XML would be the clear loser. In contrast to JSON and YAML, XML is a markup language. XML can therefore be used for more than just serializing objects.
In Listing 5, the same order was provided with additional XML features. Elements from other XML languages are now used in the document. The id Element points to a REST resource via XLink, which can be used to request representations of the order. The address has been included and the description of the second position now contains HTML markup.
The short example also shows how horrible XML documents can be. If you were to add namespaces to JSON or YAML, these would probably become just as confusing.
The structure of XML documents can be described with XML schema. Listing 6 shows an excerpt from a schema with the definition of a type for an item in an order.
The format description with XML schema offers numerous possibilities:
- With the help of the schema, XML editors can recognize and display errors or offer autocompletion
- Code for the serialization of XML documents can be generated from XML schema
- The scheme can serve as documentation
- XML documents can be validated against the schema.
The following list contains just a few examples:
- Queries with XPath and XQuery
- Transformation with XSLT
- Storage in an XML database
- Routing via an ESB
By using namespaces, elements and attributes in XML can be uniquely named worldwide. An XML document can be interpreted separately from an application. With JSON and YAML documents, the content only makes sense through the application that reads the document.
The namespaces give XML documents a context in which they can be interpreted. XML advocates therefore accuse other formats of provinciality.
With XML, the REST idea that everything is a resource can be easily implemented.
A reference to a resource can be added to any information via an XLink attribute or an enclosing element. This is not possible with JSON or YAML, although they pretend to be “web” languages.
JSON has challenged XML's sole rule and shown that it can be used for special tasks such as B. the serialization of objects is a leaner alternative. JSON and YAML also show that readability can be improved. XML still scores with its versatility, tool support and the large number of standards that are based on XML or can be combined with XML.
Introduction to JSON
YAML Ain’t Markup Language (YAML ™) Version 1.2
Extensible Markup Language (XML) 1.0 (Fifth Edition)
- Leave your dog outside of animal cruelty
- Which specifications are given for electrical devices
- Cure stem cells lung diseases
- What is something that is completely unnecessary
- Would you save private information on Evernote
- How many Wells Fargo branches are there
- Napoleon was a tyrant
- How can multicollinearity be recognized
- How did you deal with balding
- How do I start trading online 1
- How do I market a romance novel
- Who composes popular music
- Will Stellar Lumens XLM overtake the Ethereum ETH
- Do thoughts influence our daily life
- Should I move from Cleveland to Seattle?
- Why is sex education important
- What is SpaceX suing the ULA for?
- What are the benefits of ATM management
- Which is the best restaurant in Gurgaon
- When is compression used in structures
- How is the software industry in Toulouse
- What is Gmail doing right
- What is a quadcopter
- Does Cristiano Ronaldo have a tattoo
- How clouds are positively negatively charged
- Who were Frank Lloyd Wright's contemporaries?
- Is a laparoscopy a major operation?
- Why would anyone watch horror films
- How do I remember practicing coding?
- Which metals make up aluminum
- How do animate and inanimate objects differ?
- How can I track a phone number
- Can I get a tattoo
- Why does TikTok need a phone number