First off I want to start with the fact that I'm a begginer at coding , especialy C#.
Last year I've recived a program made in C# that could write XML elements to an excel file(at that point I didnt even know what kind of software).
I've just edited the program so that I could get diffrent information out of the XML files, but I've hit a wall.
I cannot seam to figure out how can I concatenate 2 identical elements of identical tags:
<Person> <PERSONID>1</PERSONID> <FIRSTNAME>VICTOR</FIRSTNAME> <LASTNAME>DAN</LASTNAME> </Person> <Person> <PERSONID>2</PERSONID> <FIRSTNAME>JHON</FIRSTNAME> <LASTNAME>SMITH</LASTNAME> </Person>`
so that the output to be DAN VICTOR/SMITH JHON. Right now I've got just the first part
persoana = string.Concat(pp.LASTNAME, " ", pp.FIRSTNAME);
so when,
sout.WriteLine(string.Concat(new string[] { "\"", person, "\"" }));
kicks in, I get 2 rows in the .csv file for each person, but if I have multiple Tags with multiple Elements then the first one of the elemets get writen properly but the rest of them get updated with the last one , thats why I was thinkging if concatenating all of the elements.
- Another problem I've encountered is when I'm facing with XMLs that do not have certain elements , then I get a DBNull error, Ive tryed to add an if statement
if (! DBNull.Value.Equals(lr.PARCELLEGALAREA.ToString())){
parcellegalarea = lr.PARCELLEGALAREA.ToString();
}
but it doesnt do the trick. The debugger keeps on showing me:
[DebuggerNonUserCode]
[GeneratedCode("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
public double PARCELLEGALAREA
{
get
{
double item;
try
{
item = (double)base[this.tableLand.PARCELLEGALAREAColumn];
}
catch (InvalidCastException invalidCastException)
{
throw new StrongTypingException("The value for column 'PARCELLEGALAREA' in table 'Land' is DBNull.", invalidCastException);
}
return item;
}
set
{
base[this.tableLand.PARCELLEGALAREAColumn] = value;
}
}
Here's a link to a simplified version of the program https://github.com/uZuRu17/Generare-Raport-CG
And also a xml file https://github.com/uZuRu17/origina_cgxml/blob/master/example3.cgxml
DBNullvalue to stringToString()and then compare with==or!=.if (lr.PARCELLEGALAREA.ToString()) == DBNull.ToString())andif (lr.PARCELLEGALAREA.ToString()) == DBNull)but thats not a valid sintax. Could you be a little more specific? Also, thank you for your timeDBNullyou have to compare it withoutToString()- e.g.if (lr.PARCELLEGALAREA == DBNull.Value). The other method is to convert to string, then compare with empty string, notDBNull.if (lr.PARCELLEGALAREA == DBNull.Value). If you want to treat null and an empty string the same way:if (lr.PARCELLEGALAREA.ToString() == string.Empty).