print an xml document to string; this can be necessary for transmitting between server and client, since XmlDocument is not serializable - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

print an xml document to string; this can be necessary for transmitting between server and client, since XmlDocument is not serializable

Demo Code

// OpenPetra.org is free software: you can redistribute it and/or modify
using System.IO;//from w  w w .ja  va 2s.c o  m
using System.Collections;
using System.Xml.Schema;
using System.Xml;
using System;

public class Main{
        /// <summary>
        /// print an xml document to string;
        /// this can be necessary for transmitting between server and client, since XmlDocument is not serializable
        /// </summary>
        /// <param name="ADoc"></param>
        /// <returns></returns>
        public static string XmlToString(XmlDocument ADoc)
        {
            StringWriter sw = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = false;
            XmlWriter xw = XmlWriter.Create(sw, settings);
            ADoc.WriteTo(xw);
            xw.Flush();
            return sw.ToString();
        }
}

Related Tutorials