Sunday, March 1, 2015

Parsing XML with .ReadXml

You can use Linq2XML and load the grid, which creates a List of objects that can be used as a datasource.


http://ift.tt/18D4SUB


What can control the Linq projection and control what is selected to be loaded to the grid.


Multiplying big numbers in different number systems

@burianvlastimil


Thanks for sharing us your solution.




We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Click HERE to participate the survey.


Parsing XML with .ReadXml

Not using the ReadXml method directly but you could just add the values yourself by looping through the colums and rows of the populated DataTable like this:



DataSet ds = new DataSet();
System.IO.StringReader sr = new System.IO.StringReader(strXML);
ds.ReadXml(sr);

foreach (DataColumn column in ds.Tables[0].Columns)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
if (string.IsNullOrEmpty(row[column.ColumnName].ToString()))
{
//add default value instead of NULL here
row[column.ColumnName] = "1";
}
}
}





Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


Parsing XML with .ReadXml

That was certainly not much of a clarification. But the code I gave you in my previous post sets the value of all empty nodes to 1. Isn't this what you wanted? Anyway, the sample code should give you the idea on how to proceed with this. Bottom line: You need to set the values yourself based on your own custom logic.


Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread and please don't expect anyone to write an entire function, class or application for you in the forums. That's not what they are for :)


Parsing XML with .ReadXml

Skip the ReadXml method and add the columns and rows to the DataTable yourself then. Something like this:



string strXML = "<root><trlFlags><trlFstmp /></trlFlags><trlFlags><trlPLU /></trlFlags></root>";

//check if the xml is properly parsed
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXML);

DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
XmlNodeList trlFlags = xmlDoc.SelectNodes("//trlFlags");
foreach (XmlNode node in trlFlags)
{
DataRow dr = dt.NewRow();
foreach (XmlNode childNode in node)
{
var existingColumn = dt.Columns.Cast<DataColumn>().FirstOrDefault(c => c.ColumnName.Equals(childNode.Name));
if (existingColumn == null)
{
dt.Columns.Add(new DataColumn(childNode.Name));

}
dr[childNode.Name] = "1";
}
dt.Rows.Add(dr);
}



Hope that helps.


Please remember to mark all helpful posts as answer to close your threads and please start a new thread if you have a new question.



Parsing XML with .ReadXml

Hi Kristin,


Thank you for your reply. The XML is provided by a third party. I don't have any control over it.


Thank you.




Remember to mark as an answer if this post has helped you.


Regarding Trigger

Hi


Please see the links for what is what


http://ift.tt/18yLari


http://ift.tt/18CMJpZ


Cheers


Bhanu