0

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? A gentle bounce on this. Is there anyway I can send my code? Its huge and exceeds the character limit. Thanks!

Retry
  • 159
  • 1
  • 3
  • 9
  • I'm not sure what your question is, you're going to parse the header files using gccXML and parse the resulting XML using the Xerces DOM parser, have I got that right?, what are you asking for exactly? – Gearoid Murphy Jul 31 '12 at 16:10
  • The task at hand is to convert a C/C++ header file into a specified XML format. So, I do the following operations on the header file: 1) Convert the header file into a gccXML format by using gccXML 2) The resulting XML is parsed using the Xerces-c DOM Parser. I want to try out reflection. The gccXML does not have enough information to construct the XML as desired. I feel. Thank you! – Retry Jul 31 '12 at 16:42
  • Yes, @GearoidMurphy you're right. – Retry Jul 31 '12 at 16:42
  • "gccXML does not have enough information". Are you sure? What information does it lack? If it does lack information [you show an example of "size" which I expect isn't in the *type* information exported by gccXML], you have difficult choices: a) revise gccXML itself (open source!) to add the information you need, b) switch to some other infrastructure that can provide this information. – Ira Baxter Jul 31 '12 at 19:04
  • ... when you get your "ideal" XML output, then what? What has "reflection" got to do with this, unless you mean "reflection as a means to get information about the code base"? – Ira Baxter Jul 31 '12 at 19:04
  • I want to switch to some other way to parse nested structures/unions as shown in the example. For instance, the gccXML description of struct3 is the following: I'm not able to figure out how to use this to generate the XML that I need. – Retry Jul 31 '12 at 19:29

1 Answers1

1

As you're already aware, gccXML has some significant limitations, there are a number of open source C++ parsers described here. Unfortunately, relfection in C++ is a lot of work for the coder (but an excellent exercise nonetheless), my favoured approach is to use the clang python API, clang is an excellent C++ parser but it's up to you to decide how to process that information (by outputting to XML or JSON). There used to be an XML printer for Clang but unfortunately I don't believe it's still active, you may be able to use an earlier build though. Best of luck!

Community
  • 1
  • 1
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
  • Thank you @Gearoid Murphy. The final output of my code has to be in a particular XML format. The catch is that for parsing functions, enums, typedefs etc I have used the gccXML description and xerces-c DOM Parser. Will I be able to use CLang just for structures? Rather, will I be able to give preferential treatment to just structures? Thank you! – Retry Jul 31 '12 at 17:19