Hi, I'm Paul, but you can also call me Todd and I won't get upset.
Paul.Todd | 25 January, 2008 00:02
Last year I decided to overhaul one of our internal modules.
This module used hand coded XML for its output along with all the attendant problems - no support for utf8 or for escaping.
In the end wrote a little class node class to build a tree and a helper class to dump the tree onto a stream such as a file or blob of memory.
Its easiest to think of the xml as having one root element node and the there are two sets of child nodes under the element, the first one is the attribute node set and the second is the child element nodes.
The "clever" thing about this tree implementation is that it allows you to chain calls together so that is makes it easier to build a tree as the supplied example shows.
The XMLGenerator class will take the root node (or any node) and then write that node and all its child nodes to the supplied stream.
The downside of this approach is that it is recursive and is also memory expensive in that all the nodes are stored in memory rather than being writton out as required.
This will be the topic for a further article
Download the example code using this link
General |
Next |
Previous |
Comments (2) |
Trackbacks (0)
gummibear | 31/07/2008, 19:45
I found that the extra space allocated for the escaped string in function XMLGenerator::WriteEncodedString was insufficient for the longer escape strings, e.g. "
Re: Generating XML
Forexx | 08/04/2008, 04:27
"The XMLGenerator class will take the root node (or any node) and then write that node and all its child nodes to the supplied stream.
The downside of this approach is that it is recursive and is also memory expensive in that all the nodes are stored in memory rather than being writton out as required. "
To mine this very strange statement, I would argue..
Excuse badly I write on inglish
http://www.toppharma.net/