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

K

Khuong Dinh Pham

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

Thx in advance
 
B

ben

Khuong said:
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
 
K

Khuong Dinh Pham

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 said:
>::std::basic_string<char,struct std:
:char_traits<char>,class std::allocator<char> >(const char *,unsigned
>' 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.
 
S

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/index.php?page=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 )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top