James Berry wrote:
Is there a way I can write to an XmlDocument using an XmlWriter style
interface efficiently in the framework 2.0?
In 1.1, you could write to a MemoryStream then load that into an
XmlDocument, but this was pretty inefficient. The XmlNodeWriter sample
helped here and I was expecting that to appear in the 2.0 framework but
it doesn't appear to be there.
Am I missing something?
XPathNavigator over an XmlDocument/XmlNode is editable in .NET 2.0 and
provides ways to feed XmlWriter output into the document/node e.g. this
XmlDocument xmlDocument = new XmlDocument();
using (XmlWriter xmlWriter =
xmlDocument.CreateNavigator().AppendChild()) {
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteEndDocument();
}
xmlDocument.Save(Console.Out);
outputs
<gods>
<god>Kibo</god>
</gods>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/