红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > Ubuntu

Ubuntu libxml2

发布时间:2007-10-05 00:23:38来源:红联作者:drivers
1:安装
mkdir /hom/libxml

sudo ./configure ./configure --prefix /home/libxml

make

make install

2:编译
g++ xmlCreator.cpp -o xmlCreator -I /home/libxml/include/libxml2/ -L /home/libxml/lib/ -lxml2

3:例子
#include
#include
#include
int main(int argc, char **argv)
{
xmlDocPtr doc = NULL;
xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;
doc = xmlNewDoc(BAD_CAST "1.0");
root_node = xmlNewNode(NULL, BAD_CAST "root");
xmlDocSetRootElement(doc, root_node);
xmlNewChild(root_node, NULL, BAD_CAST "node1",BAD_CAST "content of node1");
node=xmlNewChild(root_node, NULL, BAD_CAST "node3",BAD_CAST"node has attributes");
xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes");
node = xmlNewNode(NULL, BAD_CAST "node4");
node1 = xmlNewText(BAD_CAST"other way to create content");
xmlAddChild(node, node1);
xmlAddChild(root_node, node);
xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
文章评论

共有 0 条评论