private void updatekml()
{
XmlDocument kmlDoc = new XmlDocument();
kmlDoc.Load("XMLFile1.kml");
XmlNode xn2 = kmlDoc.SelectSingleNode("description");
XmlElement xe2 = (XmlElement)xn2;
XmlNode xn = kmlDoc.SelectSingleNode("coordinates");
XmlElement xe = (XmlElement)xn;
if(!(xe.GetAttribute("coordinates")==(str2+","+str1+","+str3)))
{
xe2.SetAttribute("description","该处经度为:"+str2+";该处纬度为:"+str1+";该处海拔为:"+str3);
xe.SetAttribute("coordinates",str2+","+str1+","+str3);
}
}以上代码运行至 if(!(xe.GetAttribute("coordinates")==(str2+","+str1+","+str3)))时说“未将对象引用设置到对象的实例”。。这是什么问题?、、、
谢谢、、、、、、、
{
XmlDocument kmlDoc = new XmlDocument();
kmlDoc.Load("XMLFile1.kml");
XmlNode xn2 = kmlDoc.SelectSingleNode("description");
XmlElement xe2 = (XmlElement)xn2;
XmlNode xn = kmlDoc.SelectSingleNode("coordinates");
XmlElement xe = (XmlElement)xn;
if(!(xe.GetAttribute("coordinates")==(str2+","+str1+","+str3)))
{
xe2.SetAttribute("description","该处经度为:"+str2+";该处纬度为:"+str1+";该处海拔为:"+str3);
xe.SetAttribute("coordinates",str2+","+str1+","+str3);
}
}以上代码运行至 if(!(xe.GetAttribute("coordinates")==(str2+","+str1+","+str3)))时说“未将对象引用设置到对象的实例”。。这是什么问题?、、、
谢谢、、、、、、、
coordinates 节点名字是不是写错了?
前面没有找到xe对应的node;
xe对应的node可能不存在coordinates属性。