我正在使用 C#.net 创建一个简单的网页,通过从 SQL 服务器加载到 XML 来播放 mp3,但是我对 XML 和 dewplayer-playlist.swf 的格式有问题,所以我想在加载时格式化 XML SQL server 使用 Dataset 将 XML 写入简单的 XML 与 dewplayer-playlist.swf 一起工作。
使用 C# 格式化 XML:
System.Xml.Xsl.XslCompiledTransform proc = new System.Xml.Xsl.XslCompiledTransform();
proc.Load(Server.MapPath("person.xslt"));
proc.Transform(Server.MapPath("person.xml"), Server.MapPath("playlist_1.xml"));
文件:person.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<xsl:for-each select="NewDataSet">
<track>
<title>
<xsl:value-of select="title"/>
</title>
<location>
<xsl:value-of select="location"/>
</location>
<album>
<xsl:value-of select="album"/>
</album>
<creator>
<xsl:value-of select="creator"/>
</creator>
<sGroupID>
<xsl:value-of select="sGroupID"/>
</sGroupID>
</track>
</xsl:for-each>
</trackList>
</playlist>
</xsl:template>
</xsl:stylesheet>
文件:person.xml
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<track>
<title>La Symphonie du Nouveau Monde</title>
<location>https://knalga.dm1.livefilestore.com/y2pAzwGFwh3A9xw86yCUf4OuRcubbLkETnkpoycw0uwV3X5h7vYjsGkSRKPBkTSjYCwfthltxwCBcwkesFK0SI9VVFdr_4tmwlSryMGpLDTpZg/SoundCloud%20Widget.mp3</location>
<album>1</album>
<creator>1</creator>
<sGroupID>1</sGroupID>
</track>
<track>
<title>La Symphonie</title>
<location>https://knyt1a.dm1.livefilestore.com/y2pvBPjLD16FTVOPyeZMU38KjzPr_mqqKj7RpvNizbkITULnctUcpwk_YAP89OB2-sNMA8eMRgnf0RtzfO-vL8ViGmwSBnQ20W75I11UMigmS8/05%20M.O.P%20-%20You%20Know%20You%20Love%20This%20%5Bprod.%20Lil%20Fame%5D.mp3</location>
<album>1</album>
<creator>1</creator>
<sGroupID>1</sGroupID>
</track>
</NewDataSet>
结果我想成为这样的 playlist_1.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>mp3/test2.mp3</location>
<creator>Antonin Dvorak</creator>
<album>La Symphonie du Nouveau Monde</album>
<title>La Symphonie du Nouveau Monde</title>
<annotation></annotation>
<duration></duration>
<image>covers/2.jpg</image>
<info></info>
<link>http://fr.wikipedia.org/wiki/Cesaria_Evora</link>
</track>
<track>
<location>mp3/test3.mp3</location>
<creator>Jean-Claude Petit</creator>
<album>Le Hussard sur le Toit</album>
<title>Le Hussard sur le Toit</title>
<annotation></annotation>
<duration></duration>
<image>covers/3.jpg</image>
<info></info>
<link>http://fr.wikipedia.org /wiki/Le_Hussard_sur_le_toit_%28film%29</link>
</track>
</trackList>
</playlist>
如何使用 # 执行此代码?