Reputation: 159
I have a structure represented as follows: (Example)
struct struct3
{
struct structchild4
{
float child5;
} child6;
unsigned int child7;
};
I want this to be represented as follows in XML:
<tag1= "struct3">
<name>struct3</name>
<input_type>byte</input_type>
<method></method>
<tag_ref = "structchild4">
<name>child6</name>
</tag_ref>
<tag2= "child7">
<name>child7</name>
<len>4</len>
<value> </value>
</tag2>
</tag1>
The method I'm following is that I'm converting this into a gccXML format and I then parse it using Visual C++. I use the xerces-c DOM parser.
Could anyone suggest how to go about doing this? Thanks!
Upvotes: 0
Views: 467
Reputation: 1736
The better way to do this is reflection, BoostLib has some ready to use. You do something like:
for( Attribute::Iterator it = reflectiveObject.getAttributeList().begin();
it != reflectiveObject.getAttributeList().end();
++it )
{
XML.createNode( it.getAttributeName() );
}
//then the same for methods. Should have an upper iterator going recursively through types, if type has a sub-class or sub-structure, then ident the XML and run the same code for them.
Without reflection is pretty more boring, you should create and Formater and a Parser for it, like
if( dynamic_cast< DesirecClass* >( obj ) != NULL ){
XML.createNode( typeid( obj ).name() );
}
// Hard Code (terrible treatment) for each attribute, etc...
There's also some demangling methods that you can search for.
Upvotes: 1