[問題] TinyXMl2適合使用讀取XML嗎

看板C_and_CPP作者 (Richard E. Bellman)時間5年前 (2018/10/29 20:03), 5年前編輯推噓3(306)
留言9則, 5人參與, 5年前最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) Win8 Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) GCC MinGW? 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) TinyXML2 問題(Question): <Staff> <Name> David Lee </Name> <ID> 1234567 </ID> <age> 38 </age> <Department> CS </Department> <Salary> 100000</Salary> </Staff> <Staff> <Name> Jeff Wu </Name > <ID> 1234568 </ID> <age> 50 </age> <Department> EE </Department> <Salary> 200000</Salary> </Staff> 以上兩個檔案要轉為 <Staff1> Name: David Lee ID: 1234567 Age: 38 Department: CS Salary: 100000 <Staff2> Name: Jeff Wu ID: 1234568 age: 50 Department: EE Salary: 200000 請問這樣適合嗎? 餵入的資料(Input): <Staff> <Name> David Lee </Name> <ID> 1234567 </ID> <age> 38 </age> <Department> CS </Department> <Salary> 100000</Salary> </Staff> 預期的正確結果(Expected Output): <Staff1> Name: David Lee ID: 1234567 Age: 38 Department: CS Salary: 100000 錯誤結果(Wrong Output): 完全沒畫面 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) https://ideone.com/20IEkW //以上跑不動 因為沒有引進tinyXML2 void TTT(){ tinyxml2::XMLDocument docXml; XMLError errXml = docXml.LoadFile("../oldData.xml"); if (XML_SUCCESS == errXml){ XMLElement* elmtRoot = docXml.RootElement(); XMLElement *elmtStaff = elmtRoot->FirstChildElement("Staff"); XMLElement *elmtName = elmtStaff->FirstChildElement("Name"); if (elmtName) { const char* pContent = elmtName->GetText(); printf( "%s", pContent); } XMLElement *elmtID = elmtName->NextSiblingElement("ID"); if (elmtID) { const char* pContent= elmtID->GetText(); printf( "%s", pContent); } XMLElement *elmtDepartment = elmtID->NextSiblingElement("Department"); if (elmtDepartment) { const char* pContent= elmtDepartment->GetText(); printf( "%s", pContent); } XMLElement *elmtSalary = elmtDepartment->NextSiblingElement("Salary"); if (elmtSalary) { const char* pContent= elmtSalary->GetText(); printf( "%s", pContent); } XMLElement *elmtAge = elmtName->NextSiblingElement(); if (elmtAge) { const char* pContent= elmtAge->GetText(); printf( "%s", pContent); } } } 補充說明(Supplement): http://www.grinninglizard.com/tinyxml2/ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.100.19.120 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1540814616.A.40A.html ※ 編輯: bellman (140.124.183.175), 10/29/2018 20:10:23

10/30 09:20, 5年前 , 1F
tinyxml沒問題,還有更快的pugixml可以用,但簡單結構建
10/30 09:20, 1F

10/30 09:20, 5年前 , 2F
議json就足夠
10/30 09:20, 2F

10/30 11:17, 5年前 , 3F
tinyxml2適不適合讀取xml? 不然tinyxml2是拿來讀什麼?
10/30 11:17, 3F

10/30 15:43, 5年前 , 4F
樓上XD
10/30 15:43, 4F

10/31 01:33, 5年前 , 5F
json不json顯然不是他可以選擇的。你接API的時候會跟他
10/31 01:33, 5F

10/31 01:35, 5年前 , 6F
們說「天啊還用什麼XML肥皂(SOAP),換json啦」嗎?
10/31 01:35, 6F

10/31 13:04, 5年前 , 7F
用過tinyxml跟minixml,處理簡單xml還算方便,但是遇到大
10/31 13:04, 7F

10/31 13:04, 5年前 , 8F
型專案,用gsoap直接從xsd長出來骨架code還是比這兩個方
10/31 13:04, 8F

10/31 13:04, 5年前 , 9F
便快速很多
10/31 13:04, 9F
文章代碼(AID): #1RrlSOGA (C_and_CPP)