无法将类型为“System.Xml.XmlElement”的对象强制转换为类型“System.Xml.XmlDocument”。
请熟悉XML的大侠帮帮忙,小弟对XML不是很了解,谢谢。现在分不多,以后补上
一.webservice中的方法
public System.Xml.XmlDocument GetUpdateDate() {
//取得更新的xml模板内容
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Update.xml"));
XmlElement root = doc.DocumentElement;
//看看有几个文件需要更新
XmlNode updateNode = root.SelectSingleNode("filelist");
string path = updateNode.Attributes["sourcepath"].Value;
int count = int.Parse(updateNode.Attributes["count"].Value);
//将xml中的value用实际内容替换
for (int i = 0; i < count; i++) {
XmlNode itemNode = updateNode.ChildNodes[i];
string fileName = path + itemNode.Attributes["name"].Value;
FileStream fs = File.OpenRead(Server.MapPath(fileName));
itemNode.Attributes["size"].Value = fs.Length.ToString();
BinaryReader br = new BinaryReader(fs);
//这里是文件的实际内容,使用了Base64String编码
itemNode.SelectSingleNode("value").InnerText = Convert.ToBase64String(br.ReadBytes((int)fs.Length), 0, (int)fs.Length);
br.Close();
fs.Close();
}
return doc;
}
二.winform后台代码
这个代码是从网上看到的。怎么自己用起来就有问题呢?希望各位大神帮帮忙!我主要是为了实现 winform自动升级功能。
localhost.WebServiceAuto Start= new localhost.WebServiceAuto(); //winform程序引用
调用System.Xml.XmlDocument doc = (System.Xml.XmlDocument)Start.GetUpdateDate();在这报错无法将类型为“System.Xml.XmlElement”的对象强制转换为类型“System.Xml.XmlDocument”。
一.webservice中的方法
public System.Xml.XmlDocument GetUpdateDate() {
//取得更新的xml模板内容
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Update.xml"));
XmlElement root = doc.DocumentElement;
//看看有几个文件需要更新
XmlNode updateNode = root.SelectSingleNode("filelist");
string path = updateNode.Attributes["sourcepath"].Value;
int count = int.Parse(updateNode.Attributes["count"].Value);
//将xml中的value用实际内容替换
for (int i = 0; i < count; i++) {
XmlNode itemNode = updateNode.ChildNodes[i];
string fileName = path + itemNode.Attributes["name"].Value;
FileStream fs = File.OpenRead(Server.MapPath(fileName));
itemNode.Attributes["size"].Value = fs.Length.ToString();
BinaryReader br = new BinaryReader(fs);
//这里是文件的实际内容,使用了Base64String编码
itemNode.SelectSingleNode("value").InnerText = Convert.ToBase64String(br.ReadBytes((int)fs.Length), 0, (int)fs.Length);
br.Close();
fs.Close();
}
return doc;
}
二.winform后台代码
这个代码是从网上看到的。怎么自己用起来就有问题呢?希望各位大神帮帮忙!我主要是为了实现 winform自动升级功能。
localhost.WebServiceAuto Start= new localhost.WebServiceAuto(); //winform程序引用
调用System.Xml.XmlDocument doc = (System.Xml.XmlDocument)Start.GetUpdateDate();在这报错无法将类型为“System.Xml.XmlElement”的对象强制转换为类型“System.Xml.XmlDocument”。
...全文
相关推荐
使用XMLDocument操作xml文件
使用XMLDocument操作xml文件,很完整的基础操作。
C#使用XmlDocument或XDocument创建xml文件
主要为大家详细介绍了C#使用XmlDocument或XDocument创建xml文件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
c#用xmlDocument等操作XML文件
简单易懂地介绍C#是如何对XML文件的读写及创建、修改操作的
C#动态生成XML
C#两种动态生成XML文件得方法,包含用DataTable生成
c#中对XML文件进行读写操作
c#中对XML文件进行读写操作c#中对XML文件进行读写操作c#中对XML文件进行读写操作


