QtDom方式写xml(二)-创新互联
struct PUBLIC_DATA_SEND { bool ifrealtimedata; bool ifdatasend; bool confirmflag; int sendtimes; int sendtime; QListwaitconfirmterminal; QList DateTimeList; char capturetime[20]; }SEND; int package_public_data(QDomDocument *doc, PUBLIC_DATA_SEND *ppublicdata, int client_num, int datatype, QDomElement *root, QDomElement *data) { QDomElement meters = doc->createElement("meters"); meters.setAttribute("total", "0"); QDomText textNode; for ( int i = 0; i < 10; i++) { QDomElement meter = doc->createElement("meter"); meter.setAttribute("id", "445"); for ( int j = 0; j < 5; j++ ) { QDomElement var = doc->createElement("var"); var.setAttribute("e", ""); var.setAttribute("e", "1"); textNode = doc->createTextNode("123.45864"); var.appendChild(textNode); meter.appendChild(var); } meters.appendChild(meter); } meters.setAttribute("total", "10"); data->appendChild(meters); return 0; } int publicdata_xm(int flag, PUBLIC_DATA_SEND *ppublicdata, char *buf, int client_num, char *name) { QDomDocument *doc = new QDomDocument(); QDomProcessingInstruction instruction; QDomText textNode; instruction = doc->createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\""); QDomElement root = doc->createElement("root"); QDomElement common = doc->createElement("common"); QDomElement building_id = doc->createElement("building_id"); QDomElement gateway_id = doc->createElement("gateway_id"); QDomElement type = doc->createElement("type"); QDomElement data = doc->createElement("data"); QDomElement time = doc->createElement("time"); doc->appendChild(root); root.appendChild(common); common.appendChild(building_id); common.appendChild(gateway_id); common.appendChild(type); root.appendChild(data); data.appendChild(time); textNode = doc->createTextNode("125479601"); building_id.appendChild(textNode); textNode = doc->createTextNode("99"); gateway_id.appendChild(textNode); textNode = doc->createTextNode("energy_data"); type.appendChild(textNode); QString datetime = "2017-03-13 15:50"; textNode = doc->createTextNode(datetime); time.appendChild(textNode); if ( flag == 1 ) { data.setAttribute("operation", "report"); } else if ( flag == 2 ) { data.setAttribute("operation", "continuous"); } else if ( flag == 3 ) { data.setAttribute("operation", "history"); } package_public_data(doc, ppublicdata, client_num, flag, &root, &data); printf("publicdata xml:\n%s\n",QString::fromLocal8Bit(doc->toByteArray()).toUtf8().data()); int len = doc->toString().replace(QRegExp(">\\s+<"),"><").toLatin1().length(); strcpy(buf, doc->toString().replace(QRegExp(">\\s+<"),"><").toLatin1()); delete doc; return len; } int main(int argc, char *argv[]) { char buf[4096]; int len = 0; len = publicdata_xm(1, &SEND, buf, 1, "dom"); printf("dom xml len = %d: \n%s\n", len, buf); return 0; }
DOM格式的xml,使用内存大,建议使用在xml内容小的情况下,dom格式的xml为树状结构,可以随意删除修改xml
站在用户的角度思考问题,与客户深入沟通,找到丹江口网站设计与丹江口网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、成都做网站、企业官网、英文网站、手机端网站、网站推广、空间域名、雅安服务器托管、企业邮箱。业务覆盖丹江口地区。输出xml内容为
125479601 99 energy_data 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864 123.45864
和
125479601 99 energy_data 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864 123.45864123.45864123.45864123.45864123.45864
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前标题:QtDom方式写xml(二)-创新互联
网站URL:http://scyanting.com/article/dpjjhs.html