Method to convert a XmlNodeList to string. - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Method to convert a XmlNodeList to string.

Demo Code

// All rights reserved.
using System.Diagnostics;
using System.Collections.Specialized;
using System.Xml;
using System.Data;
using System;/*from  ww  w  .j ava  2  s .  co m*/

public class Main{
        /// <summary>
        /// Method to convert a XmlNodeList to string.
        /// </summary>
        /// <param name="nodeList"></param>
        /// <returns></returns>
        public static string NodeListToString(XmlNodeList nodeList)
        {
            if (nodeList != null)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (XmlNode node in nodeList)
                {
                    if (sb.Length == 0)
                        sb.Append(NodeToString(node));
                    else
                        sb.Append("\r\n" + NodeToString(node));
                }
                return sb.ToString();
            }
            return "nodeList is null";
        }
}

Related Tutorials