Search code examples
.netxmltextwritersystem.xmlxmlelement

In .NET how can I write an XmlElement to an XmlTextWriter, where the element may have children


Is there an easy (single call) way in .NET to write an XmlElement to a XmlTextWriter where that element is written out in full to the output?

Where the XmlElement may have many child elements and they have children, etc. And where it explicitly adds namespaces as needed.


Solution

  • I think the WriteTo method on XmlNode (a base class of XmlElement) can do what you want.

    For the issue about namespaces I think you would better add some samples of input/output or where your current approach fails.