XML to Struct
I am iterating through an XML node with 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
Is there a better way to do this? The way I am going about it, will
result in more than a thousand lines. If I validated against a schema,
would I have to do the conversion before I stored it into the struct?
Can anyone provide a better solution for me? Thanks!
I have an XML document with the following format.
I need to take the element text content and store it in a struct:
I am parsing the XML with the following:
DOMElement* = doc->getDocumentElement();
DOMDOcument* doc = parser->getDocumentElement();
DOMXPathNXResolver* resolver = doc->createNSResolver(element);
DOMXPathResult* result = doc->evaluate(XMLString::transcode(=93//TRACK/
resolver, DOMXpathResult::ORDERED_NODE_SNAPSHOT_TYPE, NULL);
XMLSize_t len = result->getSnapshotLength();
DOMNode* node = result->getNodeValue;
char* name = XMLString::transcode(node->getNodeName());
string nodename = name;
DOMText* textnode (static_cast<DOMText*> (node->getFirstChild());
if ( textnode != NULL )
char* content = XMLString::transcode(textnode->getData());
strcontent += content;
//I would like to avoid having to do the following for each child.
There are more that 300 child nodes.
if ( nodename == =93element2=94 )
struct.element2 = atof(strcontent.c_str());