Formatting XmlTextWriter Output



So far as I can tell, that is how settings are built and applied - just like you said - they apply to the whole document and I don't believe can be set on an element/attribute basis:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter xw = XmlWriter.Create(filename, settings);

What I'm running into is where I want to assign both an attribute and content to an element, i.e. to produce

<content encoding="base64binary">encoded content here</content>

it doesn't like it unless I do a "WriteRaw" for the content:

xw.WriteStartElement("content", null);
xw.WriteAttributeString("encoding", "base64binary");
xw.WriteRaw(messageContent);
xw.WriteEndElement(); // end the content element

This comes out fine, but I was just curious if there was another, better, way?

-Tom

.


Loading