You can use an XML Reader as you have mentioned to get the InnerText property of your node. Once you have this value, you can use the
decimal.TryParse() method to properly set your decimal value (if it is invalid such as "NaN" it will be set to 0).
In order to output as you have mentioned, you can simply use
string.Format() to output as you have mentioned :
//Example to reproduce your XML structure
XmlDocument doc = new XmlDocument();
doc.LoadXml("<LTotUsed><STotalUsed><TotalUsed>1625.00</TotalUsed></STotalUsed></LTotUsed>");
XmlNodeList nodes = doc.SelectNodes("/LTotUsed/STotalUsed");
//Iterate through each of your nodes and set the values appropriately
foreach (XmlNode node in nodes)
{
//Holds your decimal value (will set to 0 if NaN or invalid)
decimal yourValue;
decimal.TryParse(node["TotalUsed"].InnerText, out yourValue);
//Output your string in the format you mentioned
string output = string.Format("The total units used is {0:00,0.00}", yourValue);
}
So if you already have an individual node all you will need to do is use the code within the loop :
//Holds your decimal value (will set to 0 if NaN or invalid)
decimal yourValue;
decimal.TryParse(node["TotalUsed"].InnerText, out yourValue);
//Output your string in the format you mentioned
string output = string.Format("The total units used is {0:00,0.00}", yourValue);
If you run into issues, you can explicitly define the CultureInfo and pass it into the string.Format() method as well :
string output = string.Format(System.Globalization.CultureInfo.GetCultureInfo("EN-US"),"The total units used is {0:00,0.00}", yourValue);
jojupi01@yah...
Member
133 Points
113 Posts
Display xmlnode.inner text
Feb 24, 2013 11:24 PM|LINK
Rion William...
All-Star
27600 Points
4566 Posts
Re: Display xmlnode.inner text
Feb 25, 2013 01:24 AM|LINK
You can use an XML Reader as you have mentioned to get the InnerText property of your node. Once you have this value, you can use the decimal.TryParse() method to properly set your decimal value (if it is invalid such as "NaN" it will be set to 0).
In order to output as you have mentioned, you can simply use string.Format() to output as you have mentioned :
//Example to reproduce your XML structure XmlDocument doc = new XmlDocument(); doc.LoadXml("<LTotUsed><STotalUsed><TotalUsed>1625.00</TotalUsed></STotalUsed></LTotUsed>"); XmlNodeList nodes = doc.SelectNodes("/LTotUsed/STotalUsed"); //Iterate through each of your nodes and set the values appropriately foreach (XmlNode node in nodes) { //Holds your decimal value (will set to 0 if NaN or invalid) decimal yourValue; decimal.TryParse(node["TotalUsed"].InnerText, out yourValue); //Output your string in the format you mentioned string output = string.Format("The total units used is {0:00,0.00}", yourValue); }So if you already have an individual node all you will need to do is use the code within the loop :
//Holds your decimal value (will set to 0 if NaN or invalid) decimal yourValue; decimal.TryParse(node["TotalUsed"].InnerText, out yourValue); //Output your string in the format you mentioned string output = string.Format("The total units used is {0:00,0.00}", yourValue);If you run into issues, you can explicitly define the CultureInfo and pass it into the string.Format() method as well :
string output = string.Format(System.Globalization.CultureInfo.GetCultureInfo("EN-US"),"The total units used is {0:00,0.00}", yourValue);