0

I have xml like this

XElement xe = "<root>
    <mynode>
        Text with link <a href=''>Test</a>
    </mynode>
</root>";

public static string GetHtmlFromXElement(this XElement xe)
{
    return xe.ToString();
}

If I use

string result = xe.Element("mynode").GetHtmlFromXElement();

I get

<mynode>Text with link <a href=''>Test</a></mynode>

But I need

Text with link <a href=''>Test</a>

How to do this right?

podeig
  • 2,597
  • 8
  • 36
  • 60

2 Answers2

1

This looks like roughly the same question, with some pretty in-depth answers.

Community
  • 1
  • 1
Mark Avenius
  • 13,679
  • 6
  • 42
  • 50
  • Thank you! I found the answer there. var reader = xe.CreateReader(); reader.MoveToContent(); return reader.ReadInnerXml().Trim(); – podeig Feb 19 '13 at 17:31
0

Try

string result = xe.Element("mynode").Value;
bytefire
  • 4,156
  • 2
  • 27
  • 36