Groups | Blog | Home
all groups > asp.net > october 2006 >

asp.net : xml to plaintext ? newbie


david.vantongerloo
10/31/2006 11:43:12 PM
hi ,

How do i get hold on text in a XML file an insert it to an ASPX page.

- <daily_statistics>
<day>1162166400.000000</day>
<user_total_credit>5859.155452</user_total_credit>
<user_expavg_credit>81.830293</user_expavg_credit>
<host_total_credit>491.812439</host_total_credit>
<host_expavg_credit>46.814941</host_expavg_credit>
</daily_statistics>


All a need is this line only :
<user_total_credit>5859.155452</user_total_credit>

To Text :
5859.155452

How ?

Morten Wennevik
11/1/2006 10:13:03 AM
Hi David,

Load your xml into an XmlDocument, then you can parse it using XPath =

queries and get the value you want. Storing your xml in a string variab=
le =

called xml you can obtain your value like this

XmlDocument doc =3D new XmlDocument();
doc.LoadXml(xml);

XmlNode node =3D =

doc.SelectSingleNode("daily_statistics/user_total_credit");
string value =3D node.InnerText;

"daily_statistics/user_total_credit" is the XPath query telling =

SelectSingleNode to get the first node matching this pattern

value =3D 5859.155452


On Tue, 31 Oct 2006 23:43:12 +0100, david.vantongerloo =

[quoted text, click to view]



-- =

Happy Coding!
david.vantongerloo
11/1/2006 12:52:44 PM
realy Thanks....



[quoted text, click to view]
Hi David,

Load your xml into an XmlDocument, then you can parse it using XPath
queries and get the value you want. Storing your xml in a string variable
called xml you can obtain your value like this

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

XmlNode node =
doc.SelectSingleNode("daily_statistics/user_total_credit");
string value = node.InnerText;

"daily_statistics/user_total_credit" is the XPath query telling
SelectSingleNode to get the first node matching this pattern

value = 5859.155452


On Tue, 31 Oct 2006 23:43:12 +0100, david.vantongerloo
[quoted text, click to view]



--
Happy Coding!
Morten Wennevik [C# MVP]

AddThis Social Bookmark Button