xmlChar *name = xmlNodeGetContent(CurNode); strcpy(data.name, name); xmlFree(name);
#include "stdafx.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlreader.h>
#include <iostream>
#include <memory>
void TestStandardIOForXml()
{
xmlDocPtr doc = NULL; /* document pointer */
xmlNodePtr one_node = NULL, node = NULL, node1 = NULL;/* node pointers */
char buff[256];
int i, j;
doc = xmlNewDoc(BAD_CAST "1.0");
std::shared_ptr<void> sp_doc(doc,[](void* doc1){
xmlDocPtr doc = (xmlDocPtr)doc1;
xmlFreeDoc(doc);
});
FILE* file = _wfopen(L"test.xml",L"wb");
if(!file)
return;
std::shared_ptr<FILE> sp_file(file,[](FILE* file){
fclose(file);
});
// 写XML的声明
xmlChar* doc_buf = NULL;
int size = 0;
xmlDocDumpMemoryEnc(doc,&doc_buf,&size,"UTF-8");
std::shared_ptr<xmlChar> sp_xc(doc_buf,[](xmlChar* doc_buf){
xmlFree(doc_buf);
});
fwrite(doc_buf,strlen((const char*)doc_buf),1,file);
xmlBufferPtr buf = xmlBufferCreate();
std::shared_ptr<void> sp_buf(buf,[](void* buf1){
xmlBufferPtr buf = (xmlBufferPtr)buf1;
xmlBufferFree(buf);
});
const char* kRootBegin = "<ROOT>";
fwrite(kRootBegin,strlen(kRootBegin),1,file);
for(int i = 0; i< 10; ++i){
one_node = xmlNewNode(NULL, BAD_CAST "one");
xmlNewChild(one_node, NULL, BAD_CAST "node1",
BAD_CAST "content of node 1");
xmlNewChild(one_node, NULL, BAD_CAST "node2", NULL);
node = xmlNewChild(one_node, NULL, BAD_CAST "node3",BAD_CAST "this node has attributes");
xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes");
xmlNewProp(node, BAD_CAST "foo", BAD_CAST "bar");
node = xmlNewNode(NULL, BAD_CAST "node4");
node1 = xmlNewText(BAD_CAST "other way to create content (which is also a node)");
xmlAddChild(node, node1);
xmlAddChild(one_node, node);
xmlNodeDump(buf,doc,one_node,1,1);
fwrite(buf->content,buf->use,1,file);
xmlUnlinkNode(one_node);
xmlFreeNode(one_node);
xmlBufferEmpty(buf);
}
const char* kRootEnd = "</ROOT>";
fwrite(kRootEnd,strlen(kRootEnd),1,file);
}
<?xml version="1.0" encoding="UTF-8"?> <ROOT><one> <node1>contentÖÐÎÄ of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one><one> <node1>content of node 1</node1> <node2/> <node3 attribute="yes" foo="bar">this node has attributes</node3> <node4>other way to create content (which is also a node)</node4> </one></ROOT>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有