-4

I create a string which contain XML code. From this string how can I get the values?

Here is the string

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <result>
        <country>India</country>
        <pincode>700001</pincode>
        <paymode>Prepaid</paymode>
        <service>Yes</service>
    </result>

I want value of service,payment,pincode.

Ani
  • 3
  • 4

1 Answers1

0

You may use XDocument for example.

var doc = XDocument.Parse(
    @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>
    <result>
        <country>India</country>
        <pincode>700001</pincode>
        <paymode>Prepaid</paymode>
        <service>Yes</service>
    </result>");


var country = doc.Root.Descendants().Single(d => d.Name == "country").Value;
var pincode = doc.Root.Descendants().Single(d => d.Name == "pincode").Value;
var paymode = doc.Root.Descendants().Single(d => d.Name == "paymode").Value;
var service = doc.Root.Descendants().Single(d => d.Name == "service").Value;
st4hoo
  • 2,196
  • 17
  • 25