xml以字符指针格式获取文本 [英] xml get text in character pointer format
本文介绍了xml以字符指针格式获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在解析xml时遇到问题. xml的结构是
Hi all,
I am facing a problem in parsing a xml. The structure of xml is
<root>
<node>
<child>abc</child>
<child>def</child>
</node>
<node>
<child>ghi</child>
<child>jkl</child>
</node>
</root>
我正在为解析xml放置一个循环,但是它不起作用
I am putting a loop for parsing the xml but it is not working
for (IXMLDOMNodePtr pChild = node->firstChild; pChild != NULL; pChild = pChild->nextSibling) {
char* result;
if ( strcmp(pChild->nodeName, "Child") == 0 ) {
char* str = pChild->text;
sprintf( targetStr, str );
sprintf( result, "%dName", i+1);
SetEnvironmentVariable( result, targetStr);
}
}
它给出了错误
}
It is giving an error
error C2451: conditional expression of type 'const struct MSXML2::IXMLDOMNodeList' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio\MyProjects\wintray\EnpaqStatus\linkState.cpp(67) : see reference to function template instantiation '__thiscall _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID _GUID_2933bf80_7b
36_11d2_b20e_00c04f983e60> >::_com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID _GUID_2933bf80_7b36_11d2_b20e_00c04f983e60> >(const struct MSXML2::IXMLDOMNodeList &)' being compiled
我的问题是如何将结构类型转换为const char *
在此先感谢
My Problem is How to convert the structure type into const char*
Thanks in advance
推荐答案
这里的问题在
行中 char * str = pChild-> text;
在此先感谢
The problem here is in the line
char* str = pChild->text;
Thanks in Advance
获得解决方案
在第
行下更改 char * str = pChild-> text;
与
_bstr_t text = pChild-> text;
char * str =文本;
谢谢大家的帮助.
Got the solution
It is change below line
char* str = pChild->text;
with
_bstr_t text = pChild->text;
char* str = text;
Thanks all for help.
在尝试解决指针问题之前,建议您先解决基础知识:这可能会使您的问题消失.
Before you try to fix your pointer problem, I suggest you fix the basics: it may make your problem disappear.
char* result;
if ( strcmp(pChild->nodeName, "Child") == 0 ) {
char* str = pChild->text;
sprintf( targetStr, str );
sprintf( result, "%dName", i+1);
除非您分配一个到result
的某个大小的缓冲区,sprintf
调用将写入哪里?
Unless you assign a buffer of some size to result
the sprintf
call will write to where?
这篇关于xml以字符指针格式获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文