西佳佳解析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的库,照着example写了一下。
运行结果什么都没有。哪个地方不对啊?
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 =
node->NextSibling()) {
tinyxml2::XMLElement *e = node->ToElement();
const char *name = e->Attribute("location");
if (name)
cout << name << ": ";
}
}
页:
[1]