I need to pick the attributes from the xml. Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<Examine>
<Categories>
<name text="test"/>
<name test="test2"/>
<name text="test3"/>
<name text="test4"/>
</Categories>
</Examine>
Here's the code, with help from the followin post: Cannot implicitly convert type system.colllections.generic
public class XmlValue
{
public System.Xml.Linq.XElement Element { get; set; }
public string Text
{
get
{
if (Element == null) return null;
return Element.Value;
}
}
}
public class XmlParser
{
public List<XmlValue> Getxml()
{
XDocument xdoc = XDocument.Load(@"D:\Web Utf-8 Converter\Categories.xml");
var list = xdoc.Descendants("Categories").SelectMany(p => p.Elements("name")).Select(e => new XmlValue {Element = e}).ToList();
var listing = list.ToList();
return listing;
}
}
How do I get the value Test,test2, test3,test4 as in the xml above?