views:

95

answers:

3

Hello Everybody,

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.

+1  A: 

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/

Ofir
Thank you very much.So as the persistent data keeps getting larger and complex we use XML.
SRec0
+1  A: 

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

stefaanv
does not this library is used for serializing objects? How can I relate this library with XML docs?
SRec0
You can specify that it serializes to XML, ofcourse then you use their format, but in the end, all you want is persistency
stefaanv
+1  A: 

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.

Zed-K