Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old October 11th, 2005, 11:15 AM
Khuong Dinh Pham
Guest
 
Posts: n/a
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, 11:25 AM
ben
Guest
 
Posts: n/a

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, 11:25 AM
sat
Guest
 
Posts: n/a

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, 11:45 AM
Mehturt@gmail.com
Guest
 
Posts: n/a

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, 11:55 AM
EventHelix.com
Guest
 
Posts: n/a

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, 12:45 PM
Khuong Dinh Pham
Guest
 
Posts: n/a

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, 01:25 PM
sat
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Require help learning how to decompose class into policies Stephen Torri answers 3 September 7th, 2007 09:15 AM
need help converting java to c++ steven acer answers 12 February 14th, 2007 11:45 PM
classes wrting/reading to binary file nightflyer answers 4 July 22nd, 2005 05:43 AM
Whitespace separating lines using extraction operator on file Kevin Grigorenko answers 18 July 19th, 2005 06:30 PM