[問題] TinyXMl2適合使用讀取XML嗎
開發平台(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
10/30 09:20, 1F
→
10/30 09:20,
5年前
, 2F
10/30 09:20, 2F
推
10/30 11:17,
5年前
, 3F
10/30 11:17, 3F
推
10/30 15:43,
5年前
, 4F
10/30 15:43, 4F
→
10/31 01:33,
5年前
, 5F
10/31 01:33, 5F
→
10/31 01:35,
5年前
, 6F
10/31 01:35, 6F
推
10/31 13:04,
5年前
, 7F
10/31 13:04, 7F
→
10/31 13:04,
5年前
, 8F
10/31 13:04, 8F
→
10/31 13:04,
5年前
, 9F
10/31 13:04, 9F