xml to plaintext ? newbie

D

david.vantongerloo

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 ?
 
M

Morten Wennevik

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
 
D

david.vantongerloo

realy Thanks....



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top