That XML isn't valid because there are no closing tags, but assuming your actual XML is valid, you can do this:
using System.Xml.Linq;
string xml = @"<language>
<record lang="".net""></record>
<record lang=""java""></record>
<record lang=""php""></record>
</language>";
string temp = string.Join(",", XDocument.Parse(xml).Root.Elements().Select(x => x.Attribute(XName.Get("lang")).Value));
- XDocument.Parse parses your string into an
XDocument
.Root
takes the root element, <language>
- .Elements() takes the child elements, the three
<record>
-tags. .Select(x => x.Attribute(XName.Get("lang")).Value)
takes the value of the "lang" attribute for each of these elements. The result is an IEnumerable<string>
.
string.Join
concatenates these strings, with a comma as separator.