This question already has answers here:
how to read a part of xml file in C++ using Libxml2
                                
                                    (3个答案)
                                
                        
                                5年前关闭。
            
                    
有我的C ++问题,我有错误,帮我:/

我想看d:

<svg>
    <g>
       <path ***d***="11"/>
    </g>
</svg>


但是我的程序不起作用:/

how to read a part of xml file in C++ using Libxml2

我的答案中的代码,UP

错误:

/home/praktyka/projects/svgreader/main.cpp:83:38:错误:从'const char *'到'const xmlChar * {aka const unsigned char *}的无效转换” [-fpermissive]



/usr/include/libxml/tree.h:1021:3:错误:正在初始化“ xmlChar * xmlGetProp(xmlNodePtr,const xmlChar *)”的参数2 [-fpermissive]

最佳答案

here读取[仅通过谷歌搜索]

xmlChar似乎是unsigned char的typedef。但是,文字字符串是const char * ...
因此,您需要将行修改为:

if(xmlGetProp(cur_node, (const xmlChar *)"d"))


为了安全起见(xmlChar是UTF8 ...您的字符串可能有所不同)...考虑查看libXML2中的相关函数,例如xmlCharStrdup

09-11 09:16