日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

tinyxml2解析XML文件

發布時間:2024/4/11 asp.net 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tinyxml2解析XML文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
tinyxml2::XMLDocument xmlDoc;tinyxml2::XMLError error = xmlDoc.LoadFile(cfgFile.c_str());if (error != tinyxml2::XML_NO_ERROR) {throw ConfigurationFileNotFound("Configuration File is failed to open");}//解析文檔// HOSTtinyxml2::XMLElement* root = xmlDoc.FirstChildElement("config")->FirstChildElement( "web");const char * contextStr = root->FirstChildElement("host")->GetText();hostConfig.host = contextStr;contextStr = root->FirstChildElement( "port" )->GetText();hostConfig.port = atoi( contextStr );// DBroot = xmlDoc.FirstChildElement("config")->FirstChildElement("db");contextStr = root->FirstChildElement("host")->GetText();dbConfig.host = contextStr;contextStr = root->FirstChildElement("port")->GetText();dbConfig.port = atoi( contextStr );contextStr = root->FirstChildElement("username")->GetText();dbConfig.username = contextStr;contextStr = root->FirstChildElement("password")->GetText();dbConfig.password = contextStr;// SFTProot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "sftp" );contextStr = root->FirstChildElement( "host" )->GetText();sftpConfig.host = contextStr;contextStr = root->FirstChildElement("username")->GetText();sftpConfig.username = contextStr;contextStr = root->FirstChildElement("password")->GetText();sftpConfig.password = contextStr;contextStr = root->FirstChildElement("remote")->GetText();sftpConfig.remote= contextStr;contextStr = root->FirstChildElement("local")->GetText();sftpConfig.local = contextStr;// Pathroot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "path" );resultPath = root->FirstChildElement( "result" )->GetText();reportPath = root->FirstChildElement( "report" )->GetText();// Resend Packroot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "multipack" );multiPackResendConfig.timeout = atoi(root->FirstChildElement("timeout")->GetText());multiPackResendConfig.maxcount = atoi(root->FirstChildElement("maxcount")->GetText());root = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "singlepack" );singlePackResendConfig.timeout = atoi(root->FirstChildElement("timeout")->GetText());singlePackResendConfig.maxcount = atoi(root->FirstChildElement("maxcount")->GetText());

下面是xml文件

<config><web><host>172.16.6.70</host><port>5055</port></web><db><host>172.16.6.78</host><port>5432</port><username>postgres</username><password>postgres</password><dbname>RemoteAssert</dbname></db><sftp><host>172.16.6.78</host><username>root</username><password>*********</password><remote>/opt</remote><local>/home/liujiayu/diagnosefile/cmdanddatafile</local></sftp><path><result>/home/liujiayu/diagnosefile/result</result><report>/home/liujiayu/diagnosefile/report</report></path><multipack><timeout>10</timeout><maxcount>3</maxcount></multipack><singlepack><timeout>3</timeout><maxcount>3</maxcount></singlepack> </config>




總結

以上是生活随笔為你收集整理的tinyxml2解析XML文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。