By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

how to read the contents of a xml file as std::string

P: n/a
How do i read the contents of a xml file and output it to a std::string.

Thx in advance
Oct 11 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
sat
The most preferred method is to use Xerces library..

check the tutorial at..

http://www-128.ibm.com/developerwork...brary/x-xercc/
bye
sat
"Khuong Dinh Pham" <kh******@gmail.com> wrote in message
news:43***********************@dtext01.news.tele.d k...
How do i read the contents of a xml file and output it to a std::string.

Thx in advance

Oct 11 '05 #2

P: n/a
ben
Khuong Dinh Pham wrote:
How do i read the contents of a xml file and output it to a std::string.

Thx in advance


template <typename CharType>
void read_file_to_string(
const CharType* filename,
basic_string<CharType>& buff)
{
ifstream fs(filename);
istream_iterator<CharType> fbegin(fs);
istream_iterator<CharType> fend;
copy(fbegin, fend, buff.begin());
}
Ben
Oct 11 '05 #3

P: n/a
the most preferred by who? I use expat http://expat.sf.net

Oct 11 '05 #4

P: n/a
TinyXML is a light weight option for reading XML files:

http://sourceforge.net/projects/tinyxml/

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based System Design and Object Modeling Tool

Oct 11 '05 #5

P: n/a

I am also using xerces to parse the xml. But now i need the xml contents
to be as std::string

I have trying to compile this code i found somewhere else:

std::ifstream ifs("file.xml");
std::string file_string( std::istreambuf_iterator<char>(ifs),
std::istreambuf_iterator<char>() );
but get this error:

: error C2664: '__thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char>
::std::basic_string<char,struct std: :char_traits<char>,class std::allocator<char> >(const char *,unsigned
int,const class std::allocator<char> &)' : cannot convert parameter 1
from 'class std::istreambuf_iterator<char,struct std::char_traits<char>' to 'const char *' No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
I am using VC6.0 compiler

Thx in advance.

sat wrote: The most preferred method is to use Xerces library..

check the tutorial at..

http://www-128.ibm.com/developerwork...brary/x-xercc/
bye
sat
"Khuong Dinh Pham" <kh******@gmail.com> wrote in message
news:43***********************@dtext01.news.tele.d k...
How do i read the contents of a xml file and output it to a std::string.

Thx in advance


Oct 11 '05 #6

P: n/a
sat
by everyone else except you..
:-)
ok jokes apart... if you look at the details.. expat is fine.. written
completely in c, has great performance results, compatible with C/C++ etc
etc..
but xerces beats expat, considering that it can go well with C/C++ and java
and also the number of OS supported..by it is far more than expat
its not enough ? ok
encodings supported by xerces are UTF 8/16 , UCS 4 , ISO8859-1 , ASCII ,
EBCDIC , CP-1252
hmmm.. expat unfortunately supports only UTF 8

So that gets its popularity..
yes.. but mind you xerces is bulky when compared to expat.

I get your next question mehturt.. "benchmarked by who" :-)
check this .. http://xmlbench.sourceforge.net/inde...ge=results.php
but mehturt.. i agree that expat is very popular parser.. so going back to
Dinh's question,
why not try out this expat.. ( I havent tried it yet )
<Me*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
the most preferred by who? I use expat http://expat.sf.net


Oct 11 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.