日期:2014-05-17  浏览次数:20360 次

一个关于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