473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Oct 11 '05 #1
6 6563
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
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
the most preferred by who? I use expat http://expat.sf.net

Oct 11 '05 #4
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
11
by: Christopher Benson-Manica | last post by:
Let's say I have a std::string, and I want to replace all the ',' characters with " or ", i.e. "A,B,C" -> "A or B or C". Is the following the best way to do it? int idx; while(...
22
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; ...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
6
by: Nemok | last post by:
Hi, I am new to STD so I have some questions about std::string because I want use it in one of my projects instead of CString. 1. Is memory set dinamicaly (like CString), can I define for...
2
by: FBergemann | last post by:
if i compile following sample: #include <iostream> #include <string> int main(int argc, char **argv) { std::string test = "hallo9811111z"; std::string::size_type ret;
6
by: SpreadTooThin | last post by:
How can I read in two characters from a file into a std::string? the long way: fstream f("myfile.bin", ios::binary | ios:in); // Opened for read binary... unsigned char buffer; buffer =...
11
by: Peter Olcott | last post by:
Does C++ have anything like this?
5
by: Ramesh | last post by:
Hi. Assuming I have a code snippet like below: #include <iostream> using namespace std; char Mac = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5 }; std::string csMac;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.