Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在libxml2(C与VS 2015)中,xmlDoc不是bool,但为什么它会说bool?_C_Xml Parsing_Visual Studio 2015_Libxml2_Xml Documentation - Fatal编程技术网

在libxml2(C与VS 2015)中,xmlDoc不是bool,但为什么它会说bool?

在libxml2(C与VS 2015)中,xmlDoc不是bool,但为什么它会说bool?,c,xml-parsing,visual-studio-2015,libxml2,xml-documentation,C,Xml Parsing,Visual Studio 2015,Libxml2,Xml Documentation,这是我的密码: #include <stdio.h> #include <libxml/parser.h> #include <libxml/tree.h> static void print_element_names(xmlNode * a_node) { xmlNode *cur_node = NULL; for (cur_node = a_node; cur_node; cur_node = cur_node->next) {

这是我的密码:

#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

static void print_element_names(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE) {
            printf("node type: Element, name: %s\n", cur_node->name);
        }
        print_element_names(cur_node->children);
    }
}

int main(int argc, char **argv)
{
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;

    if (argc != 2)  return(1);

    LIBXML_TEST_VERSION    // Macro to check API for match with
                           // the DLL we are using

                       /*parse the file and get the DOM */
        if (doc = xmlReadFile("http://www.w3schools.com/xml/note.xml", NULL, 0) == NULL){
        printf("error: could not parse file %s\n", argv[1]);
        exit(-1);
       }

       /*Get the root element node */
       root_element = xmlDocGetRootElement(doc);
       print_element_names(root_element);
       xmlFreeDoc(doc);       // free document
       xmlCleanupParser();    // Free globals
       return 0;
   }
#包括
#包括
#包括
静态无效打印元素名称(xmlNode*a_节点)
{
xmlNode*cur_node=NULL;
对于(cur_节点=a_节点;cur_节点;cur_节点=cur_节点->下一步){
if(cur\u节点->类型==XML\u元素\u节点){
printf(“节点类型:元素,名称:%s\n”,当前节点->名称);
}
打印元素名称(当前节点->子节点);
}
}
int main(int argc,字符**argv)
{
xmlDoc*doc=NULL;
xmlNode*根元素=NULL;
如果(argc!=2)返回(1);
LIBXML\u TEST\u VERSION//检查API是否匹配的宏
//我们正在使用的DLL
/*解析文件并获取DOM*/
如果(doc=xmlReadFile(“http://www.w3schools.com/xml/note.xml,NULL,0)=NULL){
printf(“错误:无法分析文件%s\n”,argv[1]);
出口(-1);
}
/*获取根元素节点*/
根元素=xmlDocGetRootElement(doc);
打印元素名称(根元素);
xmlFreeDoc(doc);//自由文档
xmlcleanuparser();//自由全局变量
返回0;
}
当我使用Visual Studio Pro 2015(Windows 8,64位)构建它时,我遇到以下错误:

  • 不能将“bool”类型的值分配给“xmlDoc*”类型的实体。

  • 错误C2440'=':无法从“bool”转换为“xmlDoc*”

  • 从代码中可以看出,xmlDoc或xmlReadFile属于bool类型,但是从这里的文档中可以看出,它们似乎都不是bool类型

    我通常用PHP编写代码,这是我的第一个C应用程序,所以我是新手

    GTK:我正在创建:文件>新建>项目>VC++>空项目


    你能告诉我我的代码有什么问题吗?如果不是数据类型。

    doc=xmlReadFile(“http://www.w3schools.com/xml/note.xml,NULL,0)==NULL
    需要
    ()
    -->
    (doc=xmlReadFile()http://www.w3schools.com/xml/note.xml“,NULL,0))==NULL
    @BLUEPIXY谢谢!!这就解决了问题。我没有注意到。