1

I want parse in C++ simple status messages from a webservice, xml fragments without encoding attribute.

<message xmlns="http://violation.importer.xyz.de/xsd">
    Der Import-Datensatz mit der Bezeichung="blabla" und der Id=68809 wurde erfolgreich importiert.
</message>

They seem to be in ISO-8859-1 . Can I set the parser to this encoding? The API is confusing to me.

Here's my code, the xml is in char* it (an iterator btw)

xmlNodePtr root_element_ptr;
xmlDocPtr xmldoc_ptr;

xmldoc_ptr = xmlReadMemory(*it, strlen(*it), "it.xml", NULL, 0);
root_element_ptr = xmlDocGetRootElement(xmldoc_ptr);
xmlNodePtr msgnode = root_element_ptr->xmlChildrenNode;
xmlChar *message = xmlNodeListGetString(xmldoc_ptr, msgnode, 1);
response_msg += *message;
response_msg += " / ";
xmlCleanupParser();
xmlFreeDoc(xmldoc_ptr);

this works, but segfaults on Umlaut character and in my log i see

it.xml:1: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE4 0x72 0x7A 0x74

so what of these do i have to use? http://xmlsoft.org/html/libxml-encoding.html

1 Answer 1

3

After posting a problem here on SO it often becomes clear and more easy. Here's what I changed and it works

xmlParserCtxtPtr ctxt_ptr = xmlNewParserCtxt();
xmldoc_ptr = xmlCtxtReadMemory( ctxt_ptr, *it, strlen(*it), "it.xml", "ISO-8859-1", 0);
//xmldoc_ptr = xmlReadMemory(*it, strlen(*it), "it.xml", NULL, 0);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.