我有一个需要解析的播放列表,我需要做一些事情,比如将它们设置在列表框中等。这里是 .xspf
<?xml version="1.0" encoding="UTF-8"?>
<playlist xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/" version="1">
<title>Playlist</title>
<trackList>
<track>
<location>file:///E:/Downloads/video1.mp4</location>
<duration>681493</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>0</vlc:id>
</extension>
</track>
<track>
<location>file:///E:/Downloads/video2.mp4</location>
<duration>614585</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>1</vlc:id>
</extension>
</track>
<track>
<location>file:///E:/Downloads/video3.mp4</location>
<duration>220629</duration>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>2</vlc:id>
</extension>
</track>
</trackList>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:node title="oh.xspf">
<vlc:node title="B">
<vlc:item tid="0"/>
<vlc:item tid="1"/>
</vlc:node>
<vlc:node title="Solo">
<vlc:item tid="2"/>
</vlc:node>
</extension>
</playlist>
这是有效的 C# 代码,但我遇到了问题,因为我使用“node.ChildNode.Item(1).InnerText”,有些文件的元数据不仅仅是“位置”“持续时间”。但我似乎无法使用元素名称来获取我想要的信息
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("1.xspf");
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("track");
string proID = "", proName = "";
foreach (XmlNode node in nodeList)
{
proID = node.ChildNodes.Item(1).InnerText;//ChildNodes.Item(1).InnerText;
//proName = node.SelectSingleNode("duration").InnerText;
listBox1.Items.Add(proID);
}
}