Hi Raymond,

Steele, Raymond <[email protected]> writes:

> I am iterating through an XML node with a many children. For each child,
> I have to store it into an associated stuct. I am looking for a quicker
> way to do this. So far, I've converted each child's text content from
> string to the correct type defined in the struct. The struct members
> are of a variety of types so I think that I have to write the code
> to determine what type it has to be converted, as I did below.
> 
> Is there a better way to do this?

Yes, XML data binding allows you to automate this provided you have
a schema describing your XML vocabulary.

You can, for example, try CodeSynthesis XSD[1] which uses Xerces-C++
underneath. Or, for a lighter-weight, dependency-free variant, you can
try CodeSynthesis XSD/e[2].

Both of these tools can either generate the struct's (actually, classes)
for you or you can use them to extract the data into your own structures.

[1] http://www.codesynthesis.com/products/xsd/
[2] http://www.codesynthesis.com/products/xsde/

Boris

-- 
Boris Kolpackov, Code Synthesis        http://codesynthesis.com/~boris/blog
Compiler-based ORM system for C++      http://codesynthesis.com/products/odb
Open-source XML data binding for C++   http://codesynthesis.com/products/xsd
XML data binding for embedded systems  http://codesynthesis.com/products/xsde

Reply via email to