MFC XML Serialization - c++

Can I serialize C++ class object to XML file using MFC Serialization. I found libraries like Boost, XML Foundation to perform this but I don't want to use any third party lib.
Is it possible in MFC C++ serialization or using any other core/native lib. Please help on this.

MFC does not have any native Xml serialization. You're either going to have to roll your own, or use a 3rd-party library. Why you have set yourself this false limitation is entirely unknown.
If it is size, or a dependency issue you are concerned about, I recommend TinyXml which you can include directly in to your C++ project and therefore have no dependencies and excellent Xml reading and writing. Note that this won't serialize an object by default, you'll have to use the class to write the Xml out yourself.
Alternatively you can look at this link in CodeProject on Xml serialization. Once again, this will require effort on your behalf.

Related

Streaming/progressive C++ XML creation library?

I'm looking for an XML library that writes out the XML stream as it goes. I've looked at TinyXML, pugixml, etc. and it seems these only write the stream when the entire DOM is built in memory. I want a library that will write each object as soon as all children and attributes are available. Is there such a thing?
The word you're looking for is SAX.
Xerces is one such C++ SAX library. If you're in the MS world then MSXML supports SAX2 too.
I wrote my own library in the end. I'm willing to share the source if it's of interest to anyone - it's a little clunky and minimal though.

Best XML Library in C++, Fast Set-Up

I was wondering what is the best XML Library in C++ (I'm using Visual Studio), considering fast set-up is critical. Basically, I want to create a file to save annotations on various .avi files.
Thank you in advance.
You should be able to get TinyXML set up and working in a matter of minutes.
TinyXML is simple enough for almost all your use (if you don't bother having the whole xml representation in memory) but other libraries offer better important features :
RapidXML is made to be really really fast. It's used in the boost::property_tree library for the xml file read/write features. If you already use boost, using directly boost::property_tree might be a good idea, if adequate, as you already can easily use it with it's simple interface.
pugiXML has been mentionned as a good replacement for RapidXML by someone on the boost mailing list, but I'm not aware of the differences.
Xerces-C++ is made to allow you high level manipulations on xml like validation using xsd files -- but is really heavy on both speed and memory size...
wrappers around classic C xml libraries (like LibXML2) might be interesting choice if you don't find what you're looking for with the previous ones...
I've used XercesC++ in the past and it was relatively painless to get working and working with.
I'm currently using MSXML and it is painful.

apple's property list (plist) implementation in c++

I'm tasked with reading Apple's property list files within a c++ application. Focusing primarily on the xml-type plist files specified in OS X, which mimic a xml-type implementation.. Apple's implementation of their property list is described here:
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html
I'm wondering if there are classes or libraries available that already can read this type of implementation within standard c++ (not Objective-C); hoping to find something rather than rolling our own. Are there any open-source implementations of this available?
PList files are not only mimicing XML, they are XML, including valid XML headers.
Any XML reader should be able to parse these files as a result. If you're looking for a logical class that abstracts the files, I'm not aware of any existing ones. Given Apple's documentation, you should be able to write one yourself with an XML reader, although it would take some work for full compatibility.
For topic starter it is too late, I know, but maybe it helps somebody
https://github.com/animetrics/PlistCpp
This is a C++ Property List (plist) serialization library (MIT license).
It supports both XML and binary versions of the plist format and is designed to
be cross platform with minimal dependencies.
Is that target-specific?
For Windows, there is a crude solution which consists of using the functions of iTunes dynamic libraries to parse plist files (either binary or plain text format work).
That's a code originally written to interface an iPod, but you can easily extract the few functions you are interested in.
The repository is on this project page: http://code.google.com/p/t-pot/
Look for the file iPoTApi.h and iPoTApi.cpp, the function TranslatePLIST of the class CiPoTApi.
I wish there were a better solution, at the time I tried to compile it from Apple's sources targeted at Windows but it is a real nightmare, and files are missing. So using their libraries was a considerable shortcut.

Minimal XML library for C++?

What XML libraries are out there, which are minimal, easy to use, come with little dependencies (ideally none), can be linked statically and come with a liberal license? So far, I've been a pretty happy user of TinyXML, but I'm curious what alternatives I have missed so far.
expat is a very fast C XML parser (although a C++ wrapper exists) that's widely used in many open-source projects. If I remember correctly, it has very few dependencies, and it's licensed under the very liberal MIT License.
I recommend rapidxml. It's an order of magnitude smaller than tinyxml, and doesn't choke on doctypes like tinyxml does.
If you need entity support or anything advanced, forget about static linking and use expat or libxml2.
FWIW there is also a version of TinyXML with a more C++-like interface, called ticpp.
There's one called libxml2.
There's also a Windows-only solution, a COM library that's part of the O/S, called msxml.
In "what’s the easiest way to generate xml in c++?" I wrote a comment that lists a few C++ XML libraries
TinyXML++ (ticpp) was, IMHO, the most appropriate for a small, easy to use XML library in C++.

Best XML serialization library for a MFC C++ app

I have an application, written in C++ using MFC and Stingray libraries. The application works with a wide variety of large data types, which are all currently serialized based on MFC Document/View serialize derived functionality. I have also added options for XML serialization based on the Stingray libraries, which implements DOM via the Microsoft XML SDK. While easy to implement the performance is terrible, to the extent that it is unusable on anything other than very small documents.
What other XML serialization tools would you folks recommend for this scenario. I don't want DOM, as it seems to be a memory hog, and I'm already dealing with large in memory data. Ideally, i'd like a streaming parser that is fast, and easy to use with MFC. My current front runner is expat which is fast and simple, but would require a lot of class by class serialization code to be added. Any other efficient and easier to implement alternatives out there that people would recommend?
The Boost Serialization library supports XML. This library basically consists in:
Start from the principles of MFC serialization and take all the good things it provides.
Solve every single issue of MFC serialization!
Among the improvements compared to MFC is support for XML.
Note that you don't necessarily control the XML schema of this serialization. It uses its own schema.
This is an age old problem. I was the team lead of the development team with the most critical path dependencies on the largest software project in the world during 1999 and 2000 and this very issue was the focus of my work during that time. I am convinced that the wheel was invented by multiple engineers who were unaware that others had already invented it. The same is true of XML Data binding in C++. I invented it too, and I've been perfecting it for over 10 years on various projects. I have a solution that addresses the issues noted here and some additional issues that repeatedly arise:
XML Updates. This is the ability to re-apply a subset of XML into an existing object model. In many cases the XML is bound to indexed objects and we cannot afford to re-index for each update.
COM and CORBA interface management. In the same respect that the XML Data Binding can be automated through object oriented practices - so can the instances of interface objects that provide that data to the application layer.
State Tracking. The application often needs to distinguish between an empty value vs. a missing value - both create an empty string. This provides the validation along with Data Binding.
The source code uses the least restrictive license - less so that GPL. The project is supported and managed from here:
http://www.codeproject.com/KB/XML/XMLFoundation.aspx
Now that it's the year 2010, I believe that nobody else will attempt to reinvent the wheel because there are a few to choose from. IMHO - this wheel is the most polished and well rounded implementation available.
Enjoy.
A good solution would be libxml. It provides lightweight SAX parsing and data structures for XML processing. There are several DOM libraries which are built on top of libxml.
Unfortunatly it is a C library, but C++ wrappers are available.
A few years ago I switched from MSXML to libxml because of the performance issues you mentioned.
If you decide to use libxml, you should also take a look at libxslt.
We use Xerces-C++. It was easy to setup and performance is good enough so we don't need to think about changing. However we aren't XML heavy.
I did listen to a podcast by Scott Hanselman (from Hansel Minutes) where they discuss the XML performance of MSXML and XSLT.
what about RapidXML, I am using it in an MFC app with some modification to support UTF-16 with std::string. I am quite satisfied with it so far.
The gSOAP toolkit auto-serializes native C and C++ data to/from XML and supports the full XML schema specification through XML data bindings:
gSOAP SourceForge Project
It has evolved since 1999 to a significant code base with code generation tools and libraries. It supports many databinding and customization features, which is especially critical for mapping XML schema types to/from the C and C++ types. It can serialize any C/C++ type and also STL containers, container templates, and cyclic data structures. It has been used in the W3C Schema Patterns for Databinding working group (with 100% schema pattern coverage success since years). There is an active open source user base and the gSOAP development functionality has been used in many industrial projects and Fortune 100 companies to develop SOAP/XML infrastructures.
This is late in the game, I just want to mention that we also use LIBXML. It's robust and reliable, and has worked well. A little bit too low-level, you'll want to build some wrappers on top of its functions.
For instance, you'll get a different sequence of function returns depending on whether you have this:
<tag attribute="value"/>
or this:
<tag attribute="value"> </tag>
Sometimes you may want that, sometimes you don't care.
We use TinyXML for all our XML needs be it MFC or straight C++.
http://sourceforge.net/projects/tinyxml