[xml] simple questions



Ah, the continuing story of a beginner (2 months ago), self-taught C++ coder...
My system is Ubuntu (so Debian really), g++ for compiling.

My little application is up and running. High time it remembered it's settings.
So I figured I'd be nice and do this in xml, with libxml2.

A rewrite of one of the site examples created an xml file, and xmlNodeGetContent
retrieves (I know a bit about DOM's).

...and now I'm stuck, because I havn't a clue how to cast the retrieved xmlchar*
into something usable as a basic data type on my system ie. a char*, or even
a c++ 'string' (the data originates as a simple string, no control characters, e.g. '48' or 'pizza').

I followed the iconv hint, only to find a cheerful GNU site telling me how to
download and run a new library. I didn't want a new library. Two
weeks later I discovered,
1. iconv is part of stdlibc
2. libxml2 includes what appear to be c wrappers for iconv
Further proof that self taught is to be taught by a very ignorant person...

My current, desperate solution is

//for a c++ string
ostringstream temp;
temp << xmlNodeGetContent(node);
SomeVariable = temp.str();

Which works, but I suspect does something horrible with the wide characters
of UTF-8. Maybe even hazardous.

Anyway, if anyone could paste a code example of how to get xmlchar* back to
the native char* of the local system, many thanks (before I bail out and try learning
about c++ i/o and interfaces with file handling...)

One other, non-xml, problem if anyone would like to help. How do I get this line,

xmlSaveFormatFileEnc(RCPath, doc, "UTF-8", 1);

to save to the current user's home directory? I presume there's
a variable I can query, or a special symbol I can use in the path
construction, somewhere.

Cheers,
Robert



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]