Thread: read XML file in c++ need urgent help

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up read XML file in c++ need urgent help

    Hi
    Code:
    I'm trying to read an XML file (below) using C++. Please help!
    
    
    <?xml version="1.0" encoding="utf-8" ?> 
    <nodes>
    <node id="n1" x="25" y="25" connection="n2,n3" /> 
    <node id="n2" x="110" y="110" connection="n1,n3,n4" /> 
    <node id="n3" x="50" y="180" connection="n1,n2,n5,n6" /> 
    <node id="n4" x="225" y="90" connection="n2,n5,n6" /> 
    <node id="n5" x="190" y="160" connection="n3,n4" /> 
    <node id="n6" x="230" y="170" connection="n3,n4" /> 
    </nodes>

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Search the Web for "C++ XML parser".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Quote Originally Posted by laserlight View Post
    Search the Web for "C++ XML parser".
    there are so many c++ xml parser available. but what is the logic to read data from xml file using c++ and display on the screen??

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by leo2008
    there are so many c++ xml parser available. but what is the logic to read data from xml file using c++ and display on the screen??
    Pick a few parsers, read their documentation, and use one that meets your needs.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    but what is the logic to read data from xml file using c++ and display on the screen??
    Do you really want to know how parsers work? I ask because it can mean years of study to understand parser theory.

    Or do you just want to get the job of parsing done? I ask because using an existing library will be fairly easy. As laserlight says, just pick one; flip a coin if you must.

    Soma

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    tinyxml and tinyxpath will probably solve all your problems.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  8. #8
    Registered User
    Join Date
    May 2012
    Posts
    3
    tinyxml seems to be the most popular one, although I have also come across tinyxml++ but have not used it yet, or liquid xml c++ tool will happily do the job as well.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by joethomas View Post
    tinyxml seems to be the most popular one, although I have also come across tinyxml++ but have not used it yet, or liquid xml c++ tool will happily do the job as well.
    Looks like the site has two versions now.
    TinyXML-2

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    If all you want to do is read XML, boost::property tree is the easiest way to go.

    It's dead simple, it's header only, so no compiling and linking libraries, and it has xpath-esque syntax for easy access to the XML data.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  2. Help with file reading...[Urgent]
    By alvifarooq in forum C++ Programming
    Replies: 19
    Last Post: 09-18-2004, 06:19 PM
  3. Problem loading file...URGENT
    By khpuce in forum C Programming
    Replies: 4
    Last Post: 05-19-2003, 08:14 AM
  4. how to delete a file?URGENT!!!!!
    By subme in forum C Programming
    Replies: 1
    Last Post: 05-12-2003, 09:32 AM
  5. Replies: 1
    Last Post: 12-01-2002, 01:24 PM