Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 11th, 2005, 10:15 AM
Khuong Dinh Pham
Guest
 
Posts: n/a
Default how to read the contents of a xml file as std::string

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

Thx in advance

  #2  
Old October 11th, 2005, 10:25 AM
ben
Guest
 
Posts: n/a
Default 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
  #3  
Old October 11th, 2005, 10:25 AM
sat
Guest
 
Posts: n/a
Default 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]


  #4  
Old October 11th, 2005, 10:45 AM
Mehturt@gmail.com
Guest
 
Posts: n/a
Default 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

  #5  
Old October 11th, 2005, 10:55 AM
EventHelix.com
Guest
 
Posts: n/a
Default 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

  #6  
Old October 11th, 2005, 11:45 AM
Khuong Dinh Pham
Guest
 
Posts: n/a
Default 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]
  #7  
Old October 11th, 2005, 12:25 PM
sat
Guest
 
Posts: n/a
Default 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]



 

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.