Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# , xml parsing. get data between tags

Tags:

c#

xml

I have a string :

responsestring = "<?xml version="1.0" encoding="utf-8"?>
<upload><image><name></name><hash>SOmetext</hash>"

How can i get the value between

<hash> and </hash>

?

My attempts :

responseString.Substring(responseString.LastIndexOf("<hash>") + 6, 8); // this sort of works , but won't work in every situation.

also tried messing around with xmlreader , but couldn't find the solution.

ty

like image 795
user257412 Avatar asked Feb 16 '26 20:02

user257412


1 Answers

Try

XDocument doc = XDocument.Parse(str);
var a = from hash in doc.Descendants("hash")
        select hash.Value;

you will need System.Core and System.Xml.Linq assembly references

like image 60
Vinay B R Avatar answered Feb 19 '26 08:02

Vinay B R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!