For a educational purposes Why should the client request a jason or xml file from the server ? What is the advantage in these files (json and xlm) and what is the difference between these files and simple txt file Programmatically
A json/xml file can be interpreted directly into the language and converted to native variables, such as arrays, strings, integers, etc. All the data also has indexes, which is very benefitial when you want to read it later on to ensure you're reading the right data. As JSON and XML are very commonly used most languages also have functions that let you encode and decode variables directly from JSON to a usable variable and vise versa.
If you were to send more information as plain text you would have to make up your own system for separating the different variables (for example separating all info with commas), but then you would run into exceptions when the text itself contiains commas. It would also be very impractical once you start receiving more information.
If your question was really meant to question the difference of putting XML inside a .xml file and a .txt file there is no difference while programming, except for the fact that storing xml in .txt would be confusing.
Normal text files are well, just text files.
They cannot be organized in a way that a machine can understand. If you needed to search for something in a text file, you need to look through every line and every word.
XML Files are a type of markup files which can be read by machines, and humans obviously. They have tags, just like HTML tags, and their format is specific to an application, so you know what tags to expect and where in the structure. This makes for easy search and readability for a machine. Not to mention, most common programming languages have support for XML Files.
JSON, similar to XML, has structure and is machine readable. Instead of tags, they are in a form known as dictionary. Their format is explained here.
You can see why it makes sense to use XML and JSON, when reading it through machines. You can even automate the entire process, since in most cases the format for a specific application is already known.
© 2022 - 2024 — McMap. All rights reserved.