0

I'm attempting to get just the inner xml of the following XML/XAML doc.

<Root>
    <Child1>
       Hello
    </Child1>

</Root>

Desired Result

    <Child1>
       Hello
    </Child1>

My code below Shows this Message

Hello

I'm expecting the Child elements as well but unable to achieve this.

Code

XDocument doc = XDocument.Parse(xx);
string fragment = (string)doc.Root.Descendants().FirstOrDefault();
Dmitry
  • 13,797
  • 6
  • 32
  • 48
IEnumerable
  • 3,610
  • 14
  • 49
  • 78

1 Answers1

0

You should be using ToString() instead of casting to string.

XDocument doc = XDocument.Parse(xx);
string fragment = doc.Root.Descendants().FirstOrDefault().ToString();
Chris Hinton
  • 866
  • 5
  • 15