For for the link, it's quite simpler now... but still SIGABRT... Still
no idea on my side...
Here is my code and the 'gdb info st' output:
*** code
#include <libxml++/libxml++.h>
#include <glibmm/convert.h>
#include <string>
#include <iostream>
int main(int argc, char **argv)
{
xmlpp::Document doc;
xmlpp::Element * elem = 0;
std::string my_encoding = "ISO-8859-1";
doc.set_internal_subset("GEDCOM", "", "gedcom60.dtd");
doc.add_comment("Generated by libgedcomparser - part of GHOSTS project");
elem = doc.create_root_node("GEDCOM");
std::string converted = Glib::convert("blah éo", "UTF-8", my_encoding);
elem->set_child_text(converted);
std::cerr << converted << std::endl;
doc.write_to_file_formatted("xmlencode.xml", my_encoding);
std::cerr << "write_to_file_formatted OK" << std::endl;
Glib::ustring result_xml;
result_xml = doc.write_to_string_formatted(my_encoding);
std::cerr << "write_to_string_formatted OK" << std::endl;
std::cerr << result_xml << std::endl;
return 0;
}
*** gdb info st:
Program received signal SIGABRT, Aborted.
[Switching to Thread 1024 (LWP 15825)]
0x403aa621 in kill () from /lib/libc.so.6
Current language: auto; currently c
(gdb) info st
#0 0x403aa621 in kill () from /lib/libc.so.6
#1 0x4017826b in raise (sig=6) at signals.c:65
#2 0x403aba53 in abort () from /lib/libc.so.6
#3 0x402f7895 in __cxxabiv1::__terminate(void (*)()) ()
from /usr/lib/libstdc++.so.3
#4 0x402f7880 in __cxxabiv1::__terminate(void (*)()) ()
from /usr/lib/libstdc++.so.3
#5 0x402f79e0 in __cxa_rethrow () from /usr/lib/libstdc++.so.3
#6 0x402ede29 in std::__throw_length_error(char const*) ()
from /usr/lib/libstdc++.so.3
#7 0x0804af61 in std::string::_Rep::_S_create(unsigned,
std::allocator<char> co
nst&) (__capacity=4294967295, __alloc= 0xbffff4c0)
at /usr/include/g++-v3/bits/basic_string.tcc:371
#8 0x0804ab98 in char* std::string::_S_construct<char const*>(char
const*, char
const*, std::allocator<char> const&, std::forward_iterator_tag) (
__beg=0x806e168 "<?xml version=\"1.0\"
encoding=\"ISO-8859-1\"?>\n<!DOCTYPE
GEDCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part
of GHOS
TS project-->\n<GEDCOM>blah éo</GEDCOM>\n", __end=0x806e167 "",
__a= 0xbffff4c0) at /usr/include/g++-v3/bits/basic_string.tcc:143
#9 0x40034674 in std::string::string(char const*, unsigned,
std::allocator<char
> const&) (this=0xbffff520,
__s=0x806e168 "<?xml version=\"1.0\"
encoding=\"ISO-8859-1\"?>\n<!DOCTYPE GE
DCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part
of GHOSTS
---Type <return> to continue, or q <return> to quit---
project-->\n<GEDCOM>blah éo</GEDCOM>\n", __n=4294967295, __a= 0xbffff4c0)
at /usr/include/g++-v3/bits/basic_string.h:666
#10 0x401c40c4 in Glib::ustring::ustring(char const*, unsigned) (
this=0xbffff520,
src=0x806e168 "<?xml version=\"1.0\"
encoding=\"ISO-8859-1\"?>\n<!DOCTYPE GE
DCOM SYSTEM \"gedcom60.dtd\">\n<!--Generated by libgedcomparser - part
of GHOSTS
project-->\n<GEDCOM>blah éo</GEDCOM>\n", n=170)
at /usr/include/g++-v3/bits/stl_alloc.h:571
#11 0x40025d27 in xmlpp::Document::do_write_to_string(Glib::ustring
const&, bool
) (this=0xbffff6a0, encoding= 0xbffff5a0, format=true) at document.cc:309
#12 0x400259b8 in
xmlpp::Document::write_to_string_formatted(Glib::ustring const
&) (this=0xbffff6a0, encoding= 0xbffff5a0) at document.cc:266
#13 0x0804a318 in main (argc=1, argv=0xbffff734) at xmlencode.cpp:25
#14 0x40398280 in __libc_start_main () from /lib/libc.so.6
Murray Cumming wrote:
On Tue, 2005-01-11 at 20:59 +0100, Cyril PICARD wrote:
I understand your comments, but I don't understand how to correctly
UTF-8-encode my string. I thought my conversion was ok since
- I use the ConvertInput function provided in the libxml2 code samples
You might have more success with the Glib::convert() methods:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__CharsetConv.html
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Libxmlplusplus-general mailing list
Libxmlplusplus-general lists sourceforge net
https://lists.sourceforge.net/lists/listinfo/libxmlplusplus-general
------------------------------------------------------------------------
#include <libxml++/libxml++.h>
#include <glibmm/convert.h>
#include <string>
#include <iostream>
#include <glibmm.h> //For g_warning()
int main(int argc, char **argv)
{
try
{
xmlpp::Document doc;
xmlpp::Element * elem = 0;
std::string my_encoding = "ISO-8859-1";
doc.set_internal_subset("GEDCOM", "", "gedcom60.dtd");
doc.add_comment("Generated by libgedcomparser - part of GHOSTS project");
elem = doc.create_root_node("GEDCOM");
Glib::ustring converted = Glib::convert("blah éo", "UTF-8", my_encoding);
//std::cerr doesn't understand utf8, but g_warning() probably does:
g_warning("converted=%s", converted.c_str());
elem->set_child_text(converted);
//This throws a "Invalid byte sequence in conversion input" Glib::Error exception
std::cerr << converted << std::endl;
doc.write_to_file_formatted("xmlencode.xml", my_encoding);
std::cerr << "write_to_file_formatted OK" << std::endl;
Glib::ustring result_xml;
//This throws an exception:
result_xml = doc.write_to_string_formatted(my_encoding);
std::cerr << "write_to_string_formatted OK" << std::endl;
std::cerr << result_xml << std::endl;
}
catch(const xmlpp::exception& ex)
{
std::cerr << "xmlpp::exception: " << ex.what() << std::endl;
return 0;
}
catch(const Glib::Error& ex)
{
std::cerr << "Glib::Error exception: " << ex.what() << std::endl;
return 0;
}
catch(const std::exception& ex)
{
std::cerr << "std::exception: " << ex.what() << std::endl;
return 0;
}
}