日期:2014-05-16 浏览次数:20459 次
protected void ReadXml()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("../admin/playlist.xml"));
if (ds.Tables.Count > 0)
{
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>/source/yqnyh.mp3</location>
<title>一千年以后</title>
</track>
<track>
<location>/source/iknow.mp3</location>
<title>我知道你离我不远</title>
</track>
</trackList>
</playlist>
XmlSerializer serializer = new XmlSerializer(typeof(playlist));
string xmlContent = File.ReadAllText("XMLFile1.xml");
using (TextReader reader = new StringReader(xmlContent))
{
playlist playList = serializer.Deserialize(reader) as playlist;
}
[XmlRoot(Namespace = "http://xspf.org/ns/0/")]
public class playlist
{
public List<track> trackList { get; set; }
[XmlAttribute]
public int version { get; set; }
}
public class track
{
[XmlElement]
public string locati