libxml2
1 声明指针: 文档指针(xmlDocPtr),结点指针(xmlNodePtr); 2 得到文档doc: xmlReadFile 3 得到根结点root_node: xmlDocGetRootElement 4 结点操作: 1)获得到结点值: xmlNodeGetContent(对应于xmlFree) 2)遍历: 指向下一个结点: xmlNodePtr ->children 结点值: xmlNodePtr->name, 结点内遍历: xmlNodePtr->next 5 释放内存: xmlFreeDoc,xmlFree 今天介绍的方法为使用Dom树解析,将给出两个实例,说明如何使用Libxml2遍历xml文档和使Xpath获取特定结点的内容值: 程序使用的xml文档为: <?xml version="1.0" encoding="UTF-8"?> <root> <node1>content of node 1</node1> <node3 attribute="yes">node has attributes</node3> <node4>other way t |