Forcing XDocument.ToString() to include the closing tag when there is no data.

Posted by JasonM on Stack Overflow See other posts from Stack Overflow or by JasonM
Published on 2010-03-17T00:21:28Z Indexed on 2010/03/17 0:31 UTC
Read the original article Hit count: 371

Filed under:
|
|
|

I have a XDocument that looks like this:

 XDocument outputDocument = new XDocument(
                new XElement("Document",
                    new XElement("Stuff")
                )
            );

That when I call

outputDocument.ToString()

Outputs to this:

<Document>
    <Stuff />
</Document>

But I want it to look like this:

<Document>
    <Stuff>
    </Stuff>
</Document>

I realize the first one is correct, but I am required to output it this way. Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ