Get Node XML - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get Node XML

Demo Code


using System.Xml.XPath;
using System.Xml;
using System.Text;
using System.IO;// w ww.ja  va 2s . c  o m
using System;

public class Main{
        public static string GetNodeXML(XmlDocument document, string XPath, string defaultValue)
        {
            return GetNodeXML(document, XPath, defaultValue, false);
        }
        #endregion

        #region GetNodeXML

        public static string GetNodeXML(XmlDocument document, string XPath, string defaultValue, bool useOuter)
        {
            try
            {
                XmlNode node = null;
                node = document.SelectSingleNode(XPath);
                if (node == null)
                    return defaultValue;
                else if (useOuter)
                    return node.OuterXml;
                else
                    return node.InnerXml;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
}

Related Tutorials