How can I get all text nodes from XML file
c#, xml
Solution
You can try this:
string input = @"
<root>
<slide>
<Image>hi</Image>
<ImageContent>this</ImageContent>
<Thumbnail>is</Thumbnail>
<ThumbnailContent>A</ThumbnailContent>
</slide>
</root>";
XDocument doc = XDocument.Parse(input);
//You can also load data from file by passing file path to Load method
//XDocument doc = XDocument.Load("Data.xml");
foreach(var slide in doc.Root.Elements("slide"))
{
var words = slide.Elements().Select(el => el.Value);
string s = String.Join(" ", words.ToArray());
}
Problem
I want to get all text nodes from an XML file. How can I do this? Example Input: ``` <root> <slide> <Image>hi</Image> <ImageContent>this</ImageContent> <Thumbnail>is</Thumbnail> <ThumbnailContent>A</ThumbnailContent> </slide> </root> ``` Expected Output: ``` hi this is A ```