Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Khuong Dinh Pham
Guest
 
Posts: n/a
#1: Oct 11 '05
How do i read the contents of a xml file and output it to a std::string.

Thx in advance

ben
Guest
 
Posts: n/a
#2: Oct 11 '05

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


Khuong Dinh Pham wrote:[color=blue]
> How do i read the contents of a xml file and output it to a std::string.
>
> Thx in advance[/color]

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
sat
Guest
 
Posts: n/a
#3: Oct 11 '05

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


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" <khuongdp@gmail.com> wrote in message
news:434b8d8e$0$84028$edfadb0f@dtext01.news.tele.d k...[color=blue]
> How do i read the contents of a xml file and output it to a std::string.
>
> Thx in advance[/color]


Mehturt@gmail.com
Guest
 
Posts: n/a
#4: Oct 11 '05

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


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

EventHelix.com
Guest
 
Posts: n/a
#5: Oct 11 '05

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


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

Khuong Dinh Pham
Guest
 
Posts: n/a
#6: Oct 11 '05

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



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>[color=blue]
>::std::basic_string<char,struct std:[/color]
: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>[color=blue]
>' to 'const char *'[/color]
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:[color=blue]
> 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" <khuongdp@gmail.com> wrote in message
> news:434b8d8e$0$84028$edfadb0f@dtext01.news.tele.d k...
>[color=green]
>>How do i read the contents of a xml file and output it to a std::string.
>>
>>Thx in advance[/color]
>
>
>[/color]
sat
Guest
 
Posts: n/a
#7: Oct 11 '05

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


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 )


<Mehturt@gmail.com> wrote in message
news:1129026705.616424.108040@o13g2000cwo.googlegr oups.com...[color=blue]
> the most preferred by who? I use expat http://expat.sf.net
>[/color]



Closed Thread