libxml2 在 C++, 设置解析器的编码 - "Input is not proper UTF-8"
libxml2 in C++, set encoding for parser - "Input is not proper UTF-8"
我想要在C++中解析来自Web服务的简单状态消息,即没有编码属性的xml片段。
<message xmlns="http://violation.importer.xyz.de/xsd">
Der Import-Datensatz mit der Bezeichung="blabla" und der Id=68809 wurde erfolgreich importiert.
</message>
它们似乎在ISO-8859-1中。我可以将解析器设置为这种编码吗?API让我感到困惑
这是我的代码,xml在char*it(迭代器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);
这是有效的,但在元音变音符上出现了segfault,在我的日志中我看到了
it.xml:1: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE4 0x72 0x7A 0x74
那么这些我必须用什么呢?http://xmlsoft.org/html/libxml-encoding.html
在SO上发布问题后,问题通常会变得更清楚、更容易。以下是我更改的内容,它有效
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);
相关文章:
- Why is UINT32_MAX + 1 = 0?
- C++错误:"error: int aaa::bbb is protected within this context"
- "input.length();"的目的是什么?
- 创建具有 new in 函数和"this is nullptr"异常的对象
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- Is !NaN not a NaN?
- 如何使用"derived input class"创建派生类?
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- Where is std::hardware_destructive_interference_size?
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- What is unordered_set in C++
- 你如何理解"std: :forward is just syntactic sugar"?这是真的吗?
- C++ "error: use of overloaded operator '*' is ambiguous"似乎只有一场比赛
- C++ is calculating wrong
- Is it good to use SDL_PIXELFORMAT_UNKNOWN?
- reference_wrapper导致"incomplete type is not allowed"
- 为什么即使在定义之后仍存在"Identifier is undefined error "?
- libxml2 在 C++, 设置解析器的编码 - "Input is not proper UTF-8"