You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Pawel Hubczak <P....@ost-poland.com.pl> on 2000/07/05 19:17:36 UTC

Building XML document from C++ structures.

I will really appreciate any comments on the proposed approaches to the problem described below. I have pointed some advantages and disadvantages that I have come up with.

The problem is as follows:
Say I have a hierarchical C++ structure which I want to dump into an XML document. The structure has its individual DTD. I'm considering three approaches:

1) Write the method which will create a DOM tree reflecting the hierarchy of the structure hierarchy and its contents. To dump the structure into an XML document, form the DOM tree and dump it into an XML document.

advantages:
- Only one method is required to create XML document - the one that dumps DOM tree into XML document. I don't need to create the methods that transform all types of structures into an XML code.
- I can freely join, navigate and modify the nodes.

disadvantages:
- Actually I will have counterparts of structures in the DOM tree, which will occupy the memory.

2) Write a method which will dump the structure directly into an XML document, without creating the DOM tree.

advantages:
- By omitting the DOM tree, I don't have counterparts of structures in the memory (see the disadvantages of the first approach).
- Whenever I need the DOM representation of the structure, I can create it using the DOM parser.

disadvantages: 
- For each type of structure I need to create the method that transforms the structure into the XML code.

3) Create a DOM tree that reflects ONLY the hierarchy of the structures, where nodes keep pointers to the data.