缺少属性值读取XML数据 [英] Reading XML data with missing attribute values

查看:101
本文介绍了缺少属性值读取XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是XML文件将数据导入到使用下面的code数据库。对于我读xml文件的投入到这一个数组对象。对于是空的属性行被错过了,无法设置为空字符串的节点。

I am using an xml file to import data into the database using the below code. For that I am reading xml file an putting that into an array object. For attributes which are null the rows are missed out and unable to set empty string for those nodes.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path + "Data.xml");
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/DocumentElement/Profile");

//read XML data and ID is one of the column
object[] ID = XDocument.Load(path + "Data.xml").Descendants("ID").Select(element => Element.Value).ToArray();

现在的ID元素空值,当我看到他们为空值的行被省略。我怎么能为那些空节点设置为空字符串值?

Now the ID element has null values and when I read them the rows with null values are omitted. How can I set empty string values for those null nodes?

推荐答案

您可以试试这个(见空COALESCE运营商??)

You can try this (See null coalesce operator ?? )

object[] ID = XDocument.Load(path + "Data.xml").Descendants("ID").Select(element => Element.Value ?? "").ToArray();

这篇关于缺少属性值读取XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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