Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-07-2011, 10:58 AM   #1
Registered: Feb 2010
Posts: 181

Rep: Reputation: 16
Working with strings in an xml file C++

I have a function that retrives text between title and links tags from an XML file, but what i want is to test if the title and link tags are between item tags. This is my code:
istringstream iss(content);
    string line;
    while(getline(iss, line))
        // get <title> and </title> positions
        int found3 = line.find("<title>");
        int found4 = line.find("</title>");
        // get <link> and </link> positions
        int found5 = line.find("<link>");
        int found6 = line.find("</link>");

        // if found tags, add them to stl::list
        if(found3 >= 0 && found4 >= 0)
            string getTitleStr = line.substr(found3 + 7, found4 - found3 - 7);
        if(found5 >= 0 && found6 >= 0)
            string getLinkStr = line.substr(found5 + 6, found6 - found5 - 6);
Does anyone have an ideea how to do this with C++ strings only ? Without parsers.And yes, i know its paitfull to implement without parsers
Thank you.
Old 03-08-2011, 06:42 AM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Please show an example of the XML file that contains the data you are attempting to parse; your opening statement was not very clear.

And btw, the STL string find() function returns a size_t value, not an int. The returned value will either be a usable index, or std::string::npos on failure. Thus checking if the return value is greater than zero (0) is not appropriate.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Searching and replacing strings in a file with strings in other files xndd Linux - Newbie 16 07-29-2010 03:40 PM
[SOLVED] Reading in a file in C, after file read null terminator at strings end gone josip76 Programming 2 05-14-2010 01:44 AM
Searching .txt file for (specific) strings and printing them to new file Hb_Kai Linux - General 7 02-18-2010 10:09 AM
guidlines on working with strings in C? zero79 Programming 1 02-22-2005 04:54 PM
Perl>>working with strings format_c Programming 2 11-15-2001 05:21 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration