用WPF做一个简单程序,从XML中取数据显示到前台界面。
我用注释掉的方法没有问题,可是用第二种方法时,总是提示错误“无效的URI,未能确定URI的格式”。路径和第一种方法是一样的,为什么就不行呢? private void Button_Click(object sender, RoutedEventArgs e)
{
//XmlDocument doc = new XmlDocument();
//doc.Load(".\\students.xml"); //XmlDataProvider xdp = new XmlDataProvider();
//xdp.Document = doc; ////students,student为XML文件中的节点
//xdp.XPath = @"/students/student"; //第二种写法,直接指定Source
XmlDataProvider xdp = new XmlDataProvider();
xdp.Source = new Uri(".\\students.xml");
xdp.XPath = @"/students/student";
this.listViewStudents.DataContext = xdp;
this.listViewStudents.SetBinding(ListView.ItemsSourceProperty,new Binding());
}
我用注释掉的方法没有问题,可是用第二种方法时,总是提示错误“无效的URI,未能确定URI的格式”。路径和第一种方法是一样的,为什么就不行呢? private void Button_Click(object sender, RoutedEventArgs e)
{
//XmlDocument doc = new XmlDocument();
//doc.Load(".\\students.xml"); //XmlDataProvider xdp = new XmlDataProvider();
//xdp.Document = doc; ////students,student为XML文件中的节点
//xdp.XPath = @"/students/student"; //第二种写法,直接指定Source
XmlDataProvider xdp = new XmlDataProvider();
xdp.Source = new Uri(".\\students.xml");
xdp.XPath = @"/students/student";
this.listViewStudents.DataContext = xdp;
this.listViewStudents.SetBinding(ListView.ItemsSourceProperty,new Binding());
}
错Uri("http://www.codinge.com);对
http://www.mscto.com/aspnet/20110912100368.html
必须加上协议名吗?我访问的是本地xml文件,是不是要加上file://前缀。还有,可以写相对路径吗?
我现在在家,不能试。。
xdp.Source = new Uri(file.FullName);