CookieMonster24 Posted July 29, 2003 Posted July 29, 2003 why is XML a better way of storing an application's configuration than INI files? Quote
karimgarza Posted July 29, 2003 Posted July 29, 2003 one of the reasons is that you can can validate the configuration Quote You're either a one or a zero. Alive or dead.
Administrators PlausiblyDamp Posted July 30, 2003 Administrators Posted July 30, 2003 Also you get a more Hierarchical structure, gives more scope for nesting of related items. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Nerseus Posted July 31, 2003 *Experts* Posted July 31, 2003 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 you'd 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 you'd have to do the validation "by hand" and it's 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 doesn't 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
*Experts* Bucky Posted August 1, 2003 *Experts* Posted August 1, 2003 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. It's insanely easy and very powerful. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.