From: Rainer S. <Rai...@so...> - 2003-12-02 15:55:12
|
I use libxml++ in a application dealing with iso-8859-2. When creating a xmlpp::Document including special characaters (valid within iso8859-2) the method-call document.write_to_string("iso-8859-2") (see code below) puts a error message to stdout: output conversion failed due to conv error Bytes: 0xB5 0x72 0x61 0x69 and the resulting xml-string is corrupted (truncated at the postion of the special character (Dec 174) What is the problem ? Do i use libxml++ in a wrong manner ? Rainer code fragment: ------------------------------------------------------------ xmlpp::Document document; xmlpp::Element* xmlPNode = document.create_root_node(theCommand+XML_CM_REQUEST); xmlPNode->add_attribute(XML_MA_XMLNS, XML_NAMESPACE_VALUE); xmlNode = xmlPNode->add_child(XML_NN_TASK); xmlNode->set_child_content(getHeaderAttr(OH_TASK_ID)); xmlNode->add_attribute(XML_MA_NAMESPACE, ourNamespace); xmlNode->add_attribute(XML_MA_VERSION, ourVersion); theRequest = document.write_to_string("iso-8859-2"); -- -------------------------------------------------------------------------- Software Factory GmbH mailto:Rai...@so... Panoramastr. 47, 73084 Salach phone : +49 7162 460592 o technical software development fax : +49 7162 460593 o system engineering mobile : +49 172 6714084 o consulting www : http://www.so-fa.de -------------------------------------------------------------------------- |
From: Christophe de V. <cde...@al...> - 2003-12-02 16:08:18
|
Rainer Stransky wrote: >I use libxml++ in a application dealing with iso-8859-2. > >When creating a xmlpp::Document including special characaters (valid within >iso8859-2) the method-call document.write_to_string("iso-8859-2") (see code >below) puts a error message to stdout: > output conversion failed due to conv error > Bytes: 0xB5 0x72 0x61 0x69 > > > iconv cannot convert your datas from UTF-8 to ISO-8859-2. >and the resulting xml-string is corrupted (truncated at the postion of the >special character (Dec 174) > >What is the problem ? Do i use libxml++ in a wrong manner ? > > > Don't forget that whatever you final document encoding is, the in-memory encoding that libxml2 uses is UTF-8. As a consequence all strings you give to libxml++ should be UTF-8 encoded. So I suggest you check that you give UTF-8 strings to the API. Cheers, Christophe |
From: Jonathan W. <co...@co...> - 2003-12-02 16:09:56
|
On Tue, Dec 02, 2003 at 04:55:07PM +0100, Rainer Stransky wrote: > I use libxml++ in a application dealing with iso-8859-2. > > When creating a xmlpp::Document including special characaters (valid within > iso8859-2) the method-call document.write_to_string("iso-8859-2") (see code > below) puts a error message to stdout: > output conversion failed due to conv error > Bytes: 0xB5 0x72 0x61 0x69 > > and the resulting xml-string is corrupted (truncated at the postion of the > special character (Dec 174) > > What is the problem ? Do i use libxml++ in a wrong manner ? I can't tell from your code snippet, but I suspect the problem is that you added ISO-8859-2 characters to the xmlpp::Document (using set_child_content() or similar). libxml2 (and therefore libxml++) uses UTF-8 as its internal encoding, so any data you read from or write to an xmlDoc (or xmlpp::Document) must be in UTF-8. If you do this: xmlNode->set_child_content("£££"); // ... theRequest = document.write_to_string("iso-8859-2"); Then libxml will try to convert the xmlDoc structure from UTF-8 to ISO-88590-2, but the "£££" data is not valid in UTF-8, so the conversion fails. When you add data to the document the data *must* be encoded in UTF-8. When libxml outputs the doc it will be in the requested encoding. Hope that helps, jon > code fragment: > ------------------------------------------------------------ > xmlpp::Document document; > xmlpp::Element* xmlPNode = > document.create_root_node(theCommand+XML_CM_REQUEST); > > xmlPNode->add_attribute(XML_MA_XMLNS, XML_NAMESPACE_VALUE); > xmlNode = xmlPNode->add_child(XML_NN_TASK); > xmlNode->set_child_content(getHeaderAttr(OH_TASK_ID)); > xmlNode->add_attribute(XML_MA_NAMESPACE, ourNamespace); > xmlNode->add_attribute(XML_MA_VERSION, ourVersion); > > theRequest = document.write_to_string("iso-8859-2"); > > > > -- > -------------------------------------------------------------------------- > Software Factory GmbH mailto:Rai...@so... > Panoramastr. 47, 73084 Salach phone : +49 7162 460592 > o technical software development fax : +49 7162 460593 > o system engineering mobile : +49 172 6714084 > o consulting www : http://www.so-fa.de > -------------------------------------------------------------------------- > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Libxmlplusplus-general mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libxmlplusplus-general -- "A scientific theory should be as simple as possible, but no simpler." - Albert Einstein |
From: Rainer S. <Rai...@so...> - 2003-12-02 16:19:56
|
Thanks, my error in understanding libxml++/libxml2. What is the favourite tool/method/procedure to convert C++-strings from ISO-8859-XX to UTF-8 ? Rainer |
From: Jonathan W. <co...@co...> - 2003-12-02 16:26:21
|
On Tue, Dec 02, 2003 at 05:19:53PM +0100, Rainer Stransky wrote: > Thanks, my error in understanding libxml++/libxml2. > > What is the favourite tool/method/procedure to convert > C++-strings from ISO-8859-XX to UTF-8 ? on the command line, iconv(1) in code, iconv(3) jon -- "Subvert the dominant paradigm!" - The I.O.D. |