当前位置: 代码迷 >> ASP.NET >> 一个关于xml读取的有关问题··坐等求解
  详细解决方案

一个关于xml读取的有关问题··坐等求解

热度:2309   发布时间:2013-02-25 00:00:00.0
一个关于xml读取的问题··坐等求解
public static string GetNodeInfoByNodeName(string path,string nodeName)
  {  
  string XmlString="";
  XmlDocument xml=new XmlDocument();
  xml.Load(path);
  System.Xml.XmlElement root=xml.DocumentElement;
  System.Xml.XmlNode node=root.SelectSingleNode("//"+nodeName);
  if (node!=null)
  {
  XmlString=node.InnerText;
  }
  return XmlString;
  }
报 :用户代码未处理NullReferenceException
  未将对象引用设置到对象的实例

------解决方案--------------------------------------------------------
哪一行保存,看看xml.DocumentElement存在吗
------解决方案--------------------------------------------------------
只能说你xpath写的不对
------解决方案--------------------------------------------------------
XMLDocment操作看看MSDNhttp://msdn.microsoft.com/en-us/library/fb63z0tw.aspx
  相关解决方案