Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am using an xml file to import into the database using the below code.
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();

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?
Posted
Updated 16-Nov-15 18:14pm
v2
Comments
Sergey Alexandrovich Kryukov 17-Nov-15 0:16am    
How those null values are expressed in XML?
—SA
vignesht50 17-Nov-15 0:17am    
the attribute is missed out for few rows which has empty node values. So the attribute ID by itself is not present.
Sergey Alexandrovich Kryukov 17-Nov-15 0:20am    
This is not null... :-)
—SA
vignesht50 17-Nov-15 0:22am    
Could I call it empty string values?
Sergey Alexandrovich Kryukov 17-Nov-15 0:28am    
Normally, empty string will result in a non-null string with empty content...
It all depends on the model/schema (conventions). For example, XSI schema defines special namespace to define nil and other reference-related entities. See, for example,
http://docstore.mik.ua/orelly/xml/schema/ch11_03.htm...
You are doing ad-hoc parsing (which is bad for maintainability), so you can define attribute carrying the information that the node takes its mandatory place and signifies null reference.
—SA

1 solution

Look at the answers to this question where the authors of the answer post briefly reviewed the problem: http://stackoverflow.com/questions/774192/what-is-the-correct-way-to-represent-null-xml-elements[^].

See also my comments and another link I provided…

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900