Copy XML Attribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Copy XML Attribute

Demo Code

// All rights reserved.
using System.Diagnostics;
using System.Collections.Specialized;
using System.Xml;
using System.Data;
using System;/*from w ww . j  a  v a 2 s  . c om*/

public class Main{
        #endregion 
        
      #region More Attribute Methods
      public static bool CopyAttribute( XmlNode fromNode, XmlNode toNode, string attributeName ) 
      { 
         bool success = false; 
         XmlDocument doc = toNode.OwnerDocument; 
         string val = ""; 
         if ( GetAttributeValue( fromNode, attributeName, ref val ) ) 
         { 
            if ( toNode.Attributes[attributeName] == null ) 
            { 
               CreateAttribute( toNode, attributeName, val ); 
            } 
            success = SetAttributeValue( toNode, attributeName, val ); 
         } 
         return success; 
      }
}

Related Tutorials