CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2008
    Posts
    163

    XML Parsing using C++

    Hi,

    My requirement is this. I have an .XML file. Using this file i would like to drive my program.
    For the same i would like to parse my .XML file. Which C++ headers and class files will help me to do this. Give few reference spots also.

    I am using VS 2008.

    Thanks
    Dave

  2. #2
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: XML Parsing using C++

    you can use Tiny XML
    http://sourceforge.net/projects/tinyxml/
    or you can use Full C++ Toolkits like QT or Wxwigdet
    they provide more comprehensive development

  3. #3
    Join Date
    Apr 2008
    Posts
    163

    Re: XML Parsing using C++

    I don't want to use a third party library.

    I want to use native C++ for doing the same .

    Let me know the header file for support this.

    Thanks
    Dave

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: XML Parsing using C++

    I'm not shure what you understand by "native C++". if you mean std c++ then no there is no xml parser class.
    Kurt

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: XML Parsing using C++

    Quote Originally Posted by Dave1024 View Post
    I want to use native C++ for doing the same .
    Let me know the header file for support this.
    There aren't any standard C++ classes that do XML parsing.

    Either you use one of the well-established C++ XML parsers out there ( a google search will reveal them to you), or you have to write your own.

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: XML Parsing using C++

    there is not such thing a native C++ , ( except if you take into account STL which is again a library ) , try to separate in your mind the libraries which are used by C++ to language construct C++ ( which is keyword and syntax which make the language)
    So my suggestion would be to go with third party library.

  7. #7
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: XML Parsing using C++

    Quote Originally Posted by Dave1024 View Post
    I have an .XML file. Using this file i would like to drive my program.
    If you are using this file to configure your program, then XML might not be the format of choice.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: XML Parsing using C++

    Quote Originally Posted by aamir121a View Post
    there is not such thing a native C++
    Well, there is, but that term is usually used as a contrast to Managed C++/CLI which is not what the OP intended.

    The C++ Standard Libraries do not include XML parsers. Boost (which is sort of the standard library's extended family) may have something, I'm not sure.

    The one I've used in the past to good effect is libxml2. It's not very hard to use.

  9. #9
    Join Date
    Oct 2008
    Posts
    1,456

    Re: XML Parsing using C++

    Quote Originally Posted by Lindley View Post
    Boost (which is sort of the standard library's extended family) may have something, I'm not sure.
    there is boost property tree; it's easy to use, STL-like and very flexible but it supports only basic xml-parsing, no validation of any sort, xpath or transforms, just a translation of the xml tree into a std::map like tree container. It's very helpful because of its interaction with iostream and boost lexical cast which makes insertion/extraction of "properties" in the tree easy and expressive; moreover, it has the added benefit of parsing from/to different file formats, like json and ini.

    Quote Originally Posted by monarch_dodra
    If you are using this file to configure your program, then XML might not be the format of choice.
    I thought xml was the most common format in this scenario, isn't it ?

  10. #10
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: XML Parsing using C++

    I thought xml was the most common format in this scenario, isn't it ?[/QUOTE]

    XML is mostly used to transfer or store structured data, in some form of universal format.

    If the requirement is just have a file to describe your program's configurations at startup, the using XML is overkill. A good old fashion textual .ini file well get the work done just as well.

    Since the op wasn't very clear about his needs, I just thought I'd throw it in there.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured