Thread: How do I parse an XML file?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    Question How do I parse an XML file?

    Good morning,


    I've been trying with various libraries (everything from pugixml to RapidXML) but have been unable to parse a simple XML file. I want to grab all the inner text of each page->text into separate std::string's., so 1 page per std::string.


    My RapidXML attempt: https://ideone.com/XWylb


    My pugiXML attempt: https://ideone.com/RzN6X


    XML file: https://ideone.com/wrG13


    Can you help me get one to work?


    Thanks for all suggestions,


    Alec Taylor


    PS: Preferably I would like the RapidXML one to work.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Maybe it has something to do with the way that
    > if(mode=="XML")
    is NOT the way you compare two char* pointers.
    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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Try tinyxml. Google it.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    Quote Originally Posted by Salem View Post
    Maybe it has something to do with the way that
    > if(mode=="XML")
    is NOT the way you compare two char* pointers.
    I know I'm meant to use strcmp, but that isn't the cause of the problem.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    Exclamation

    Quote Originally Posted by VirtualAce View Post
    Try tinyxml. Google it.
    Just tried with tinyxml++, couldn't get it to work: https://ideone.com/yC1l8

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I know I'm meant to use strcmp, but that isn't the cause of the problem.
    Prove it!

    > 1>Build FAILED.
    Have all your attempts at using various libraries ended with something like this?

    If so, then STOP scouting around for yet another library to use and actually READ the library instructions for how to compile and link a program for a given library.
    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.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    Nope, only the pugixml and tinyxml++ have ended like that, RapidXML partially works.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    Figured out the rapidxml version.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to parse this file?
    By zcrself in forum C++ Programming
    Replies: 9
    Last Post: 04-19-2010, 03:51 AM
  2. Parse a file
    By L_U_K_E in forum Windows Programming
    Replies: 1
    Last Post: 04-03-2007, 05:20 AM
  3. How can I parse data from a file
    By figo2476 in forum C Programming
    Replies: 5
    Last Post: 08-19-2005, 08:07 AM
  4. Resource file parse error
    By WDT in forum Windows Programming
    Replies: 13
    Last Post: 03-09-2004, 06:42 PM
  5. Parse error in .rc file.
    By Ranedhel in forum Windows Programming
    Replies: 1
    Last Post: 07-29-2003, 02:52 PM

Tags for this Thread