我用tinyxml2的库来进行解析xml,运行结果什么都没有。
要求输出运行结果是
位置1
位置2
位置3
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/"
xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/">
<title>歌手姓名</title>
<trackList>
<track>
<album>Winnie Ho - Finally Chapter 01 (2016)
/</album>
<title>01 - Me and Myself.mp3</title>
<location>位置1</location>
<duration>172000</duration>
</track>
<track>
<album>Winnie Ho - Finally Chapter 01 (2016)
/</album>
<title>02 - Keep in Touch.mp3</title>
<location>位置2</location>
<duration>200000</duration>
</track>
<track>
<album>Winnie Ho - Finally Chapter 01 (2016)
/</album>
<title>03 - Missing.mp3</title>
<location>位置3</location>
<duration>207000</duration>
</track>
</trackList>
</playlist>
下面是我的代码
====================
tinyxml2::XMLDocument doc;
doc.Parse(xml);
tinyxml2::XMLHandle docHandle(&doc);
tinyxml2::XMLElement *entry = docHandle.FirstChildElement("location")
.ToElement();
if (entry) {
for (tinyxml2::XMLNode *node = entry->FirstChildElement(); node; node =2
node->NextSibling()) {
tinyxml2::XMLElement *e = node->ToElement();
const char *name = e->Attribute("location");
if (name)
cout << name << ": ";
}
}
|