Proper use of XML

Over the past couple of years, I have seen many articles, opinions on how XML is redundant or misused.

When should I use XML? What specific examples exist that your average programmer can work with this, no doubt XML is one of the best solutions? Are there any good articles / books that solve this problem (and not articles about why XML is NOT suitable)?

+4
source share
6 answers

XML was developed primarily as a document markup language, and its widespread adoption for the exchange of structured data was something unexpected (for me, at least). It is worth recalling why this happened (compared to pre-existing options such as CSV, ASN.1 or custom formats such as EDI and Swift). It was a Unicode-compatible format, and was rich enough to represent fairly complex data; free ready-made parsers were available, they were easy to read, which facilitates debugging and can be checked using the schema language (in fact, the choice of schema languages). It comes with its high-level declarative processing languages ​​in the form of XSLT, XPath, and more recently, XQuery. But it carries baggage from its origin in the world of documents - baggage that is important for some data-oriented applications (because, in truth, most of the data has a narrative text in it somewhere), but not for everyone. It has never been designed with the limitations of existing programming languages, and this is the biggest reason people are looking for alternatives. JSON and YAML provide many original advantages without baggage, but not for everyone - for many applications the lack of a powerful schema language is a serious drawback. However, if you want to use the language mainly for exchanging data between procedural programs, without the need for a scheme and without the need for rich text, JSON may suit you,

+2
source

I use xml IFF, I need a human-readable (for certain definitions of readable), hierarchical, verified (scheme / relaxation), compatible (from application to application or even serialized object) storage format.

I also use it when the goal is to allow third-party tools to convert data to other presentations (xsl-> docbook, xhtml, etc.).

If you need a private / internal data format, xml is about as crowded as you can get.

+2
source

The beauty of XML lies in the fact that it allows the transfer of structured information between systems that otherwise could not communicate effectively. For example, between two databases. Thus, a valid use case for XML can be made in this case, and XML parsers and output functions are usually implemented in DBMS solutions. My answer may be too wise to answer such a broad question as yours, but I believe that the value that XML brings to the table is the ability to share structured information between incompatible technologies.

+1
source

For cross-platform compatibility, I like the fact that XML, XPath, XML Schema, XSLT and XHTML, etc. are standards defined and supported by W3. This includes a number of XML standards (UBL, GML, etc.). This gives you a high degree of confidence that when I use XML to exchange data between systems, I will get the expected results and that many standards exist to begin with.

Despite the fact that JSON is undoubtedly a more efficient XML solution, it has a wider range of capabilities. If I were creating one application, I would consider JSON. If I wanted to build a service-oriented architecture spanning many systems based on a standardized exchange format, then I would go with XML - as I know, this will cover almost all requirements. In many situations, this may be superfluous, but in the few where he was able to do something, JSON could not. I would be glad if I chose the heavyweight approach. If I were building one part of this architecture, I could curse that the architect chose XML when my needs were covered by JSON. But there will be a guy in the city who needs all of his namespaces and schemas to build his part.

+1
source

A good use seems to be dependency injection (a la the Spring). This allows for greater flexibility in configuring and reconfiguring applications without rebuilding.

This is the only context in which I have used it, and I find it very useful.

0
source

I have to say that I honestly never use XML again. If I need to store properties outside the code base, I use the properties file (key = value). When writing web services, I use JSON as the glue that ties my two applications together.

The only exception was for a project where the provider preferred to use XML. This is a .NET store and they prefer SOAP and XML. The data I received contained N records of 10 children each, and the information was analyzed and stored in a database.

For me, the only time I will use XML is to speak the language of other systems that also speak about XML.

-1
source

Source: https://habr.com/ru/post/1337247/


All Articles