1

I have a couple of questions about XML.

Can XML be used for normal c++ application instead of using a text file ?

If so, does this method have advantages?

and finally, how can I use XML to store data? what tools are needed?

Regards.

3 Answers 3

1

You can use XML for storing information - it's less Human readable than a text file, but can be more easily communicated with other systems and coding languages. If all you need is a few text/numeric properties, stick to a property file. If you need a mix of configuration options, and you want to use validation (can be accomplished using XML schema), automatic modification (e.g. XSL transformations) or communicate it easily with Web Services, than XML is useful. If you want to store binary data, XML is probably not that answer. Though you can store it in a filesystem and use the XML for the metadata (i.e. where each file is located).

Take a look at Apache Xerces-C for C++ XML code - http://xerces.apache.org/xerces-c/

1
  • Thank you very much. So as the persistent data keeps getting larger and complex we use XML.
    – SRec0
    Feb 3, 2010 at 10:41
1

XML can be parsed as a text file by your application. There are libraries available.
Advantage: the files can be exchanged with other applications more easily, especially if you provide an XML-schema file.
Storing data in XML can be done with boost.serialization

2
  • does not this library is used for serializing objects? How can I relate this library with XML docs?
    – SRec0
    Feb 3, 2010 at 10:43
  • You can specify that it serializes to XML, ofcourse then you use their format, but in the end, all you want is persistency
    – stefaanv
    Feb 3, 2010 at 10:49
1

It depends of the kind of data you want to read/write, but XML is generally a good way to go for storing structured and hierarchical datas.

You can use librairies such as TinyXML to easily parse and write XML files in C++.

The main drawback is that XML is verbose ; that's why you can also use an alternative such as JSON to store your datas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.