I ahve experience serializing/deserializing XML files but I have never had to parse just a single statement, so I'm not sure how to go about this.
I have a string that holds this:
<Vol Model_Type="Flat">102.14</Vol>
And, I want to extract just the 102.14.
Should I use XPath, or is there a simpler option?
If you're using .NET 3.5 or above, use LINQ to XML. For example:
string x = "<Vol Model_Type=\"Flat\">102.14</Vol>";
XElement element = XElement.Parse(x);
decimal value = (decimal) element;
XML handling doesn't get much simpler than that :)
Of course, that's assuming you don't care about the element name or the attribute. If you do, LINQ to XML will still make it easy for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With