根目录App_Data下的Departments.xml数据如下:
<Departments>
<Collage>
<name> 基础医学院 </name>
<value> jcyxy </value>
</Collage>
<Collage>
<name> 中医药学院 </name>
<value> zyyxy </value>
</Collage>
<Collage>
<name> 生物医学工程学院 </name>
<value> swyxgcxy </value>
</Collage>
......
</Departments>
要把它绑定dropdownlist的项里面,请问代码怎么写,或怎么通过数据源控件绑定?
请高人指点!
------解决方案--------------------------------------------------------
用dataset读XML文件
------解决方案--------------------------------------------------------
DataSet ds = new DataSet();
ds.ReadXML( "XML文件的全路径 ");
Console.Write(ds.Tables[0].Rows[0][ "bookname "].ToString());
------解决方案--------------------------------------------------------
use XPath, "//Author[name= 'Jane ']/price ", for example
authors.xml:
<Authors>
<Author>
<name> Mark </name>
<price> 2200 </price>
</Author>
<Author>
<name> Jane </name>
<price> 3500 </price>
</Author>
<Author>
<name> Tom </name>
<price> 4000 </price>
</Author>
</Authors>
testxml.aspx:
<%@ Import Namespace= "System.Xml " %>
<script language= "C# " runat= "Server ">
void Page_Load(Object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath( "authors.xml "));
XmlElement el = (XmlElement)xmldoc.SelectSingleNode( "//Author[name= 'Jane ']/price ");
if (el != null)
Response.Write( "Jane 's price: " + el.InnerText);
else
Response.Write( "Jane Not found ");
el = (XmlElement)xmldoc.SelectSingleNode( "//Author[name= 'Jack ']/price ");
if (el != null)
Response.Write( "Jack 's price: " + el.InnerText);
else
Response.Write( "Jack Not found ");
}
</script>