0
        string s = @"<body><div class=""item"">123</div>***<div class=""item""><div class=""main"">456</div></div></body>";
        using (var sr = new StringReader(s))
        {
            var xdoc = XDocument.Load(sr);
            var elements = xdoc.Descendants("div").Where(x => x.Attribute("class").Value == "item");
            foreach (var element in elements)
            {
                Console.WriteLine(element.Value);
            }
        }

expected

123
<div class="main">456</div>

but actualy is

123
456

now i'm using string.Join(Environment.NewLine, element.Nodes()) to get a proper value, but I dislike it, too complex for this easy task.

Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
  • Turns out there is no easy way to do it - see [this thread](http://stackoverflow.com/questions/3793/best-way-to-get-innerxml-of-an-xelement) – Andrei Mar 05 '14 at 17:32
  • An HTML Parser that exposed the DOM (HTML Agility Pack, MSHTML) would make it easier – Alex K. Mar 05 '14 at 17:38

0 Answers0