Trouble Parsing XML with Mixed Content in C# - Text Nodes Not Captured
I keep running into I'm refactoring my project and Quick question that's been bugging me - I'm relatively new to this, so bear with me... I'm currently working on an XML parsing task using C# with the `System.Xml.Linq` namespace, and I am running into an issue with mixed content. The XML structure I'm dealing with has both text and elements nested within the same parent node, and it seems that only the element nodes are being parsed correctly. Here's a simplified version of my XML: ```xml <root> <item> Some introductory text. <subitem>Value 1</subitem> More text after subitem. <subitem>Value 2</subitem> </item> </root> ``` My current code is trying to read these nodes and capture both the text and the elements. However, when I execute this snippet: ```csharp XDocument doc = XDocument.Load("path/to/your/file.xml"); var items = doc.Descendants("item").Select(x => new { SubItems = x.Elements("subitem").Select(s => s.Value).ToList(), TextBefore = x.Nodes().OfType<XText>().FirstOrDefault()?.Value, TextAfter = x.Nodes().OfType<XText>().LastOrDefault()?.Value }).ToList(); ``` I am getting `null` for `TextBefore` and `TextAfter`, which means I am not capturing the text nodes outside of the `<subitem>` tags. I tried using `x.Nodes()` to access all nodes but it seems that `XText` nodes are not being considered properly. Is there a better way to handle mixed content in this scenario? I've read that using `XElement.Value` might not be appropriate for mixed content due to how it retrieves a single string, but I'm at a loss on how to extract all the text nodes surrounding the elements accurately. Any insights or code examples would be appreciated! This issue appeared after updating to Csharp 3.9. I'm on macOS using the latest version of Csharp.