如何将xml字段(在xml中不存在)作为null传递? [英] how to pass a xml field(which doesnt exist in xml) as null?

查看:389
本文介绍了如何将xml字段(在xml中不存在)作为null传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取一个xml文件我有字段INTERNALID和BOATTYPE但字段ALI不在xml文件中...如何将xml文件中不存在的字段传递为NULL?

下面是我的代码



I am reading a xml file i have fields INTERNALID and BOATTYPE but field ALI is not there in the xml file...how to pass the fields which doesnt exist in the xml file as NULL?
below is my code

boatInfo.internalId = int.Parse(node["INTERNALID"].InnerText);
                   boatInfo.boatType = node["BOATTYPE"].InnerText;
                   boatInfo.boatModel = (node["ALI"].InnerText);

推荐答案

因此,您应该检查它是否存在。做类似下面的事情。

So, you should check if it exists or not. Do something like below.
if(node["ALI"] == null)
{
    // Node does not exist, do whatever you want to do.
}


我在下面的链接中得到答案

http://stackoverflow.com/questions/12004903/check-xml-node-is-exist-or-not [ ^ ]



感谢您的回复
i got d answer in the below link
http://stackoverflow.com/questions/12004903/check-xml-node-is-exist-or-not[^]

Thanks for the replies


这篇关于如何将xml字段(在xml中不存在)作为null传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆