开发平台(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/