先列出xml文件部分数据
<?
xml version="1.0" encoding="utf-8"
?>
< File >
< FileNode Name ="BGS" Type ="" Path ="/" />
< FileNode Name ="DaoShiJT" Type ="aspx" Path ="/BGS" />
< FileNode Name ="DianFei" Type ="aspx" Path ="/BGS" />
</ File >
在文件中拖入一个XmlDataSource,输入XPath。
< File >
< FileNode Name ="BGS" Type ="" Path ="/" />
< FileNode Name ="DaoShiJT" Type ="aspx" Path ="/BGS" />
< FileNode Name ="DianFei" Type ="aspx" Path ="/BGS" />
</ File >
XPath2.0 distinct-values(/File/FileNode/@Path),测试失败,提示没有distinct-values方法
XPath1.0 preceding-sibling::FileNode | ../preceding-sibling::File/FileNode)/@Path)]/@Path,测试没错误,但怎么也查不到纪录。难道这个语句错了,在XmlSpy软件中测试,无论XPath2.0还是XPath1.0语句,测试都是期望的结果。郁闷了好长时间,将前台页面中的XmlDataSource移到后台,代码如下:
1
XmlDocument doc
=
new
XmlDocument();
2 doc.Load(Request.PhysicalApplicationPath + @" File.xml " );
3 XmlNodeList nodeList = doc.DocumentElement.SelectNodes( @" /File/FileNode[not(@Path = (preceding-sibling::FileNode | ../preceding-sibling::File/FileNode)/@Path)]/@Path " );
4 this .DropDownList1.DataSource = nodeList;
5 DropDownList1.DataTextField = " Value " ;
6 DropDownList1.DataValueField = " Value " ;
7 DropDownList1.DataBind();
测试成功,得到正确的值了。
2 doc.Load(Request.PhysicalApplicationPath + @" File.xml " );
3 XmlNodeList nodeList = doc.DocumentElement.SelectNodes( @" /File/FileNode[not(@Path = (preceding-sibling::FileNode | ../preceding-sibling::File/FileNode)/@Path)]/@Path " );
4 this .DropDownList1.DataSource = nodeList;
5 DropDownList1.DataTextField = " Value " ;
6 DropDownList1.DataValueField = " Value " ;
7 DropDownList1.DataBind();
根据实验发现
1、ASP.NET还不支持XPath2.0
2、对于复杂的XPath,前台好像不怎么支持
当然这是我一己之见,还望各高手指点。