gpt4 book ai didi

c - libXML 检索子项时出错 - 不返回更多子项的内容

转载 作者:行者123 更新时间:2023-11-30 15:14:37 24 4
gpt4 key购买 nike

好吧,我一直在绕这个圈子。我正在尝试将 XML 文件/数据解析为一些结构。

由于每个子元素都需要执行特定的业务逻辑,因此我决定创建单独的过程来管理每个子元素。

原始 xml 可以在这里找到:http://hearme.fm/ars.xml

我可以管理 DAAST 元素,然后将其馈送到 Ad 元素,但是当我尝试进入 Inline 元素时。 node->name 返回:“Text”,我似乎无法得到比这更进一步的信息。

有人能透露一下吗?

谢谢

#ifndef DAASTXML_C_
#define DAASTXML_C_

#define XMLSTR(str) ((xmlChar *)(str))

#include "daastXML.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <stdio.h>
#include <stdlib.h>

void parseAds(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile);
void parseInline(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile);
void parseCreatives(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile);

void daastParser (char *filePath){

xmlDocPtr doc;
xmlNodePtr node;

doc = xmlParseFile(filePath);
node = xmlDocGetRootElement(doc);

struct daastXML xmlFile;

if (xmlStrcmp (node->name, XMLSTR("DAAST")) == 0){
xmlFile.version = (char *)xmlGetProp(node, XMLSTR("version"));

parseAds(doc, node->children, xmlFile);

}
xmlFreeDoc(doc);

}

void parseAds(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){

vectorAds_init(&xmlFile.Ads);

do {
if (node == NULL) break;
if (xmlIsBlankNode(node)) continue;

if (xmlStrcmp (node->name, XMLSTR("Ad")) == 0) {

struct daastAd newAd;
newAd.id = (char *)xmlGetProp(node, XMLSTR("id"));
newAd.sequence = (char *)xmlGetProp(node, XMLSTR("sequence"));

// At this point we need to get the inline (or wrapper) info *** WRAPPER NOT INTEGRATED ***
printf("\nAdvert ");
printf("\n");

parseInline (doc, node->children, xmlFile);

vectorAds_append(&xmlFile.Ads, newAd);
}
} while ((node = node->next));
}

void parseInline (xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){

printf("\nInline : node name: ");
printf(node->name);

if (xmlStrcmp (node->name, XMLSTR("InLine")) == 0){
printf("We've got the inline element");
}

parseCreatives (doc, node->children, xmlFile);
}

void parseCreatives(xmlDocPtr doc, xmlNodePtr node, struct daastXML xmlFile){

printf("\nCreatives \n");

}

最佳答案

在@kaylum的帮助下,我似乎找到了答案。

我添加了以下内容:

我已将此例程添加到 parseInline 进程中,并且现在似乎可以工作

do {
if (node->type == XML_ELEMENT_NODE){
printf(node->name);
break;
}
} while((node = node->next));

即它循环遍历父级的所有子级,当它返回 Element_Node 时我可以对该节点进行操作。

关于c - libXML 检索子项时出错 - 不返回更多子项的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34008702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com