Set Item Value in XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Set Item Value in XmlNode

Demo Code

// All rights reserved.
using System.Diagnostics;
using System.Collections.Specialized;
using System.Xml;
using System.Data;
using System;//  w w  w .  ja  va  2  s.com

public class Main{
        // Set uint32 value in a node
        public static bool SetItemValue(XmlNode node, string itemName, UInt32 value)
        {
            bool success = false;
            if (node != null && node[itemName] != null)
            {
                node[itemName].InnerText = value.ToString();
                success = true;
            }
            return success;
        }
        // Set int32 value in a node
        public static bool SetItemValue(XmlNode node, string itemName, Int32 value)
        {
            bool success = false;
            if (node != null && node[itemName] != null)
            {
                node[itemName].InnerText = value.ToString();
                success = true;
            }
            return success;
        }
        #endregion

        #region SetItemValue(node, name, value)
        // Set string value in a node
        public static bool SetItemValue(XmlNode node, string itemName, string value)
        {
            bool success = false;
            if (node != null && node[itemName] != null)
            {
                node[itemName].InnerText = value;
                success = true;
            }
            return success;
        }
}

Related Tutorials