I have a xml file as follows:
<Root>
<Folder1>
<file>AAA</file>
<file>BBB</file>
<file>CCC</file>
</Folder1>
<Folder2>
<file>AAA</file>
<file>BBB</file>
<file>CCC</file>
</Folder2>
</Root>
I need all the parents in a list of string, I tried using
using (XmlTextReader reader = new XmlTextReader(pathFiles))
{
reader.ReadToFollowing("file");
string files = reader.ReadElementContentAsString();
}
So, "files" variable contains only “AAA” ,
reader.ReadElementContentAsString()
doesn't accept List.
Is there any way to extract the output as {“AAA”,”BBB”,”CCC”, AAA”,”BBB”,”CCC”}
XDocument doc=XDocument.Load(xmlPath);
List<string> values=doc.Descendants("file")
.Select(x=>x.Value)
.ToList();
Try this
XDocument xdoc = XDocument.Parse(xml);
var filesArray = xdoc.Elements()
.First()
.Descendants()
.Where(x => x.Name == "file")
.Select(x => x.Value)
.ToArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.