XML Advantage???

XML is very basic by itself. But there are related technologies, such as XSL, XSLT, Schemas and more that build on the basics of XML.

If you wanted, you could build an XML file with an embedded (or external) schema. The schema could define exactly what the XML had to look like including what parameters existed, their datatypes, max lengths, whether you could have one "row" or more, what fields were required to be present, what values they could contain (maybe a list), and much much more. In an INI file you *could* do that, but youd have to build the validation mechanism yourself. Using schemas, which follow well defined standards, you can use built in validation in the XmlValidator objects to determine whether an XML file is valid.

As a simple example, say you wanted some initialization file to contain a location to a database and a timeout value. The schema could say that the DB location was a string and must be there. The timeout value is an integer from 0 to 300 and is optional (with a default of 30). The schema could be embedded in your application while the XML initialization file is loaded dynamically at runtime (like an INI file). Through a call to a validator, you could determine whether the XML file passed in was valid or not.

You could do the same thing with an INI file, but youd have to do the validation "by hand" and its all custom code to do the validation. While it may be easier to do by hand in this example, imagine reading in 20, 50, or 100 settings. The XML schema validation is very fast and doesnt require any custom code. It *does* require knowing how to code a schema of course :)

As PlausiblyDamp pointed out, XML is also hierarchical and can easily contain large chunks of data. That helps support more dynamic and user-friendly files.

Also, INI files would have problems reading in values that contained carriage returns or line feeds, especially if the value of a key looked like another key. XML can embed special characters in CDATA blocks (or converting the characters to a special syntax, in some cases).

-Nerseus
 
In the .NET Framework, if you were just looking to store data for your application without
having to transfer it between different mediums, you could use
serialization to save and load a class in XML (using the
SoapFormatter), or in the much more compact binary (using the
aptly-named BinaryFormatter), to go between a saved file and a
class instance in only a few (say 2 or 3) lines of code. Its insanely
easy and very powerful.
 
Back
Top