Thread: XML parsing with C++

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    XML parsing with C++

    I am trying to parse an xml document and extract certain information, I am new to all this so sorry if i come across as a reall newb.

    My file would have multiple contacts in the file. I am trying to extract and output only certain bits of contact info depending on what postcode, county, city etc they live in. I want the code to be usable in C++ format.

    What would be the best way to do this and is there a tool that will do it for me?

    thanks in advance for reading.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Are you open to using a library to do all the grunt work?

    Xerces-C++ XML Parser
    or
    The Expat XML Parser
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    boost::property_tree is a lightweight solution to this, it doesn't have anywhere near the features of a dedicated xml-parser but it's extremely easy to use.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Google tinyxml.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    3
    hi jachstws7, dont worry about it, i am fairly new to c++ as well, however I have started using tinyxml++ and liquid xml c++, both of which are pretty good but if you want lightweight, tiny is the better choice.

  6. #6
    Registered User sirama's Avatar
    Join Date
    Jun 2012
    Location
    Bangalore
    Posts
    7
    I also suggest Liquid XML. It is good for C++ code base and has rich functions placed in. MSXML also a good one, but I don't know why people hate it.

  7. #7
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Quote Originally Posted by sirama View Post
    MSXML also a good one, but I don't know why people hate it.
    Are you frakkin' kidding me?? MSXML becomes somewhat bearable only once you've built a wrapper around it that totally hides the fact that MSXML is somewhere underneath it.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by antred View Post
    Are you frakkin' kidding me?? MSXML becomes somewhat bearable only once you've built a wrapper around it that totally hides the fact that MSXML is somewhere underneath it.
    That's larely due to using a C interface from C++, which can be the case with any API.
    MSXML itself is actually very good and I would also recommend it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Xerces is a fine piece of software as long as you do not look at the output it creates. Some of those files are uber nasty. But what Xerces can do is amazing and is akin to the XML support available in .NET.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I've had good experiences with pugixml recently. It's a new library, but seems stable, and it has a more modern C++ style than many others. But Tinyxml is okay too, and definitely more widely used.

    I used expat once and it was really complicated, minixml was way simpler -- this was in C though, not C++. Still, you may want to go for somewhat smaller/simpler libraries to start with. As you can tell, there are a lot of XML libraries out there! Here's a list if you're curious. Free C/C++ XML Parser Libraries
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing Xml
    By deviousdexter in forum C# Programming
    Replies: 7
    Last Post: 04-24-2009, 06:29 AM
  2. CSV Parsing
    By spadez in forum C++ Programming
    Replies: 13
    Last Post: 02-04-2009, 10:28 AM
  3. C parsing
    By CM_2020 in forum C Programming
    Replies: 5
    Last Post: 07-08-2008, 10:33 AM
  4. String parsing(parsing comments out of HTML file)
    By slcjoey in forum C# Programming
    Replies: 0
    Last Post: 07-29-2006, 08:28 PM
  5. Parsing XML
    By CompiledMonkey in forum C# Programming
    Replies: 2
    Last Post: 05-03-2002, 07:08 AM