XML file and text files!

15,185

Solution 1

XML means a structured document, standard Validation and description tools (DTD, Schema), and a standardized way of parsing them (i.e. DOM)

"Raw" text files might mean easier to write (no need to respect any tag imbrication or anything), but as they don't necessarily have a well-defined structure, they can get harder to parse.

Solution 2

There many advantages in general. It depends what is your case and what of them are applicable to you. To start, the txt file contains only data but there are no indicators what this data mean. Also, the structure of the data in txt is fixed and it's not documented in the txt itself.

With XML you have lots of additional technologies you can use - XSD for validating the structure of the XML document - to check whether it's correct and fulfill your requirements. Also, you've got XSL (and XSLT with it) for transforming this document in desired shape and format. And of course the XPath for searching, selecting and extracting data from your XML document.

Of course, the obvious disadvantage of XML is the bigger size, for the same amount of data. So, it's a trade off here. You should consider whether this trade off is useful in your case.

Solution 3

It all depends on the context, but in general:

Advantages:

  • Most languages come with an xml parser, which makes it easy to load and parse the data
  • XMLs hierarchical nature maps well to an object hierarchy, therefore it's easy to map from one to the other
  • It's application agnostic.
  • There are a variety of bolt-on technologies, such as XSLT, XPath and XQuery that allow you to manipulate the data.

Disadvantages:

  • It's verbose and may lead to unnecessary noise in your data.
  • It's not compact, which can be an issue if you are transmitting the data
  • Parsing can be a lot slower that just reading a line from a CSV file (for example) and splitting it based on a separator.
Share:
15,185
Johanna
Author by

Johanna

Updated on June 04, 2022

Comments

  • Johanna
    Johanna over 1 year

    I want to know the advantages of using an XML file over a text file?please help me thanks!

  • anthares
    anthares over 13 years
    What do you mean by "better performance", actually there is a big overhead of the amount of data. And transferring it around is a big of a heck. That's why JSON was introduced for Client-Server communication in AJAX for example.