0

The XML below represents a FIX message. This message has a variable number of fields (numbered using the id tag), each containing differing attributes. So I would like to parse this XML and with my additional coding abilities output a C++ message object which includes all the attribute information per field.

enter image description here

First question would be- is there a boost library which I can use to do this? My second question would be what is the interface between what the XML parser can provide and where I have to write code to create the objects. So for example, in the XML on line 8 there is a <delta/> tag and this is an attribute of the object. So for field 52 (line 8) the attribute would be a Delta sub type object but for line 9 the attribute would be a Copy subtype object. I would like to store these subtypes in an std::unordered_map with the field ID being the key.

I guess another way of wording this is- what "end result" will the XML parser give me to help build the objects the way I want them?

user997112
  • 29,025
  • 43
  • 182
  • 361

1 Answers1

0

You should probably use one of the many commonly-used xml parsers, Xerces and TinyXML are two possibilities. There are more. Google is your friend.

You want to run in SAX mode rather than DOM mode (the documentation for the parser you choose will explain). That means the parser will call code you supply for each element and attribute it parses rather than building an arbitrary structure in memory that doesn't match your domain-specific needs.

Dale Wilson
  • 9,166
  • 3
  • 34
  • 52
  • I just came across Boost.PropertyTree, what do you think about this? http://akrzemi1.wordpress.com/2011/07/13/parsing-xml-with-boost/ – user997112 Apr 07 '14 at 22:16
  • I've used boost property tree. I have mixed emotions about as a collection of properties -- it tries to support XML, JSON, .INI (and possibly others) and suffers from some "least-common-denominator" issues, but other that that it's OK. However... – Dale Wilson Apr 08 '14 at 13:53
  • In your case you don't need the alternate formats, so I would go with a "real" XML parser rather than a package that happens to be able to parse XML. Particularly since boost properties is DOM-like. It reads the data to its own internal structure from which you must pull it rather than "pushing" the data to your app like SAX does. (To me the "push" approach is cleaner.) – Dale Wilson Apr 08 '14 at 13:54