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!

6
  • 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? Commented Jul 31, 2012 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! Commented Jul 31, 2012 at 16:42
  • Yes, @GearoidMurphy you're right. Commented Jul 31, 2012 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. Commented Jul 31, 2012 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"? Commented Jul 31, 2012 at 19:04

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.