TinyXML 解析 XML 格式的字符串返回 NULL?
我正在尝试使用 TinyXML 来解析 XML 格式的字符串。但返回指针始终为NULL。我不确定哪部分代码设置错误。
TiXmlDocument docTemp;
const string strData = "<?xml version=\"1.0\" ?><Hello>World</Hello>";
const char* pTest = docTemp.Parse(strData.c_str(), 0 , TIXML_ENCODING_UTF8);
if(pTest == NULL){
cout << "pTest is NULL" << endl;
}
它总是显示“pTest 为 NULL” 有什么想法吗?
非常感谢!
I'm trying to use TinyXML to parse a string with XML format. But the return pointer is always NULL. I'm not sure which part of code is setting wrong.
TiXmlDocument docTemp;
const string strData = "<?xml version=\"1.0\" ?><Hello>World</Hello>";
const char* pTest = docTemp.Parse(strData.c_str(), 0 , TIXML_ENCODING_UTF8);
if(pTest == NULL){
cout << "pTest is NULL" << endl;
}
It always shows 'pTest is NULL'
Any idea?
Thanks a bunch!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果出现错误,它应该返回 0,但看起来 TiXmlBase::SkipWhiteSpace 中存在错误,如果右括号后面没有字符,则返回 0,但如果有空格或 \r 或 \n,则返回指针。因此,您有两个选择在右括号后添加一些白色字符,或者将 SkipWhiteSpace: 开头的以下行修改为
:
It should return 0 in the case of an error but looks like there is bug in TiXmlBase::SkipWhiteSpace, if there is no character after the closing bracket it returns 0, but if there is a white space or \r or \n it returns the pointer. So you have 2 options add some white character after the closing bracket or modify the following lines in at the beginning of SkipWhiteSpace:
to something like:
看起来解析成功时返回 null。
您能看到 docTemp.RootElement() 是否包含有效元素吗?
It seems like the parse returns null on success.
Can you see if docTemp.RootElement() contains a valid element ?
看起来
TiXMLDocument::Parse
在失败的情况下返回NULL
,而在解析成功时返回指向右尖括号旁边的字符的指针。Looks like
TiXMLDocument::Parse
returnsNULL
in the case of failure and the pointer to the character next to closing angle bracket, when parsing was succesful.