我使用tinyxml2来处理包含 xml 的字符串。我使用该函数Parse
,但它只是读取字符串的一部分并返回XML_SUCCESS
#include "XML/include/tinyxml2.h"
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
std::string xml("<application> <name>something</name> </application>");
tinyxml2::XMLDocument xmlDoc;
if (tinyxml2::XML_SUCCESS == xmlDoc.Parse(xml.c_str(), xml.size()))
{
tinyxml2::XMLElement* pNode = xmlDoc.FirstChildElement("name");
std::cout << pNode->GetText() << std::endl;
}
return 0;
}
它会抛出一个异常,告诉我pNode
是 anullptr
并且我检查_charBuffer
了 xmlDoc 的。
它只包含
<application