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,使用內(nèi)存大,建議使用在xml內(nèi)容小的情況下,dom格式的xml為樹(shù)狀結(jié)構(gòu),可以隨意刪除修改xml
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到丹江口網(wǎng)站設(shè)計(jì)與丹江口網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:做網(wǎng)站、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋丹江口地區(qū)。輸出xml內(nèi)容為
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
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。