Re: [libxml++] ISO-8859-2 enocdings



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:Rainer Stransky so-fa de
> 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
> Libxmlplusplus-general lists sourceforge net
> https://lists.sourceforge.net/lists/listinfo/libxmlplusplus-general

-- 
"A scientific theory should be as simple as possible, but no simpler."
	- Albert Einstein




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