開發平台(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/