C# 使用SelectSingleNode读取标签报 Object reference not set to an instance of an object.错误

今天在读XML文档时报Object reference not set to an instance of an object,发现如下:

product.ProductId = xmlnode.SelectSingleNode("ProductId").InnerText;
//错误  因为这里的ProductId 在XML文件里面是大写的,所以找不到内容。由此可见此方法是大小写敏感的

product.ProductId = xmlnode.SelectSingleNode("ProductId".ToUpper()).InnerText;
//正确  转化为大写读取成功

猜你喜欢

转载自blog.csdn.net/weixin_39730950/article/details/81182522