我看到可以在C#中编写一个xml文件,但是我可以将扩展名更改为.xspf吗?
手动执行时语法非常相似
我希望用户使用属性和要导出的.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>./07%20The%20Punishment.mp3</location>
<title>The Punishment</title>
<album>Manos Hadjidakis: 15 Vespers</album>
<trackNum>7</trackNum>
<duration>125840</duration>
**<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:id>0</vlc:id>
<vlc:option>bookmarks={name=omilitis1,bytes=-1,time=14},{name=omilitis2,bytes=-1,time=66},{name=omilitis3,bytes=-1,time=102}</vlc:option>
</extension>**
</track>
</trackList>
<extension application="http://www.videolan.org/vlc/playlist/0">
<vlc:item tid="0"/>
</extension>
答案 0 :(得分:0)
试试xml linq
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string playListTitle = "Playlist";
string location = "./07%20The%20Punishment.mp3";
string trackTitle = "The Punishment";
string album = "Manos Hadjidakis: 15 Vespers";
int trackNumber = 7;
int duration = 125840;
string bookmarks = "bookmarks={name=omilitis1,bytes=-1,time=14},{name=omilitis2,bytes=-1,time=66},{name=omilitis3,bytes=-1,time=102}";
string header = "<?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\">" +
"</playlist>";
XDocument doc = XDocument.Parse(header);
XElement playlist = (XElement)doc.FirstNode;
XNamespace ns = playlist.GetDefaultNamespace();
XNamespace vlcNS = playlist.GetNamespaceOfPrefix("vlc");
XElement tracklist = new XElement(ns + "tracklist");
XElement extension = new XElement(ns + "extension");
playlist.Add(new object[] {
new XElement(ns + "title", playListTitle),
tracklist,
new XElement(ns + "extension", new object[] {
new XAttribute("application", "http://www.videolan.org/vlc/playlist/0"),
new XElement(vlcNS + "item",
new XAttribute("tid",0)
)
})
});
tracklist.Add(new object[] {
new XElement(ns + "track", new object[] {
new XElement(ns + "location", location),
new XElement(ns + "title", trackTitle),
new XElement(ns + "album", album),
new XElement(ns + "trackNum", trackNumber),
new XElement(ns + "duration", duration),
extension
})
});
extension.Add(new object[] {
new XAttribute("application", "http://www.videolan.org/vlc/playlist/0"),
new XElement(vlcNS + "id", 0),
new XElement(vlcNS + "option", bookmarks)
});
}
}
}