我正在尝试将元素添加到已经存在的节点/父级中,如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<BitComet Version="1.0">
<MyShares>
<bt title="Sound of Music" save_path="C:\Downloads|Sound of Music" task_finished="true" category="software" size="7126369" hash="31e0ded5b561ed698c151e72d5f20d9b75f03b12"/>
</MyShares>
</BitComet>
--
TiXmlDocument xml(pf);
if(!xml.LoadFile()) return;
TiXmlElement* root = xml.FirstChildElement("BitComet");
TiXmlElement* parent = xml.FirstChildElement("MyShares")
TiXmlElement* elem = new TiXmlElement( "bt" );
elem->SetAttribute("title", "TiTlE");
elem->SetAttribute("save_path", "C:\\Downloads|Test");
elem->SetAttribute("task_finished", "true");
elem->SetAttribute("category", "software");
elem->SetAttribute("size", 7126369);
elem->SetAttribute("hash", "hash_here");
xml.LinkEndChild( elem );
xml.LinkEndChild( parent );
xml.LinkEndChild( root );
xml.SaveFile(pf);
我不确定发生了什么,但是当它执行那段代码时它会崩溃。