Creates child nodes that would resemble a table whose values are passed in parameter XML attribute Values. - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Creates child nodes that would resemble a table whose values are passed in parameter XML attribute Values.

Demo Code


using System.Diagnostics;
using System.Collections.Specialized;
using System.Xml;
using System.Data;
using System;/*w  w  w.j av  a  2s .c o m*/

public class Main{
        /// <summary>
      /// Creates child nodes that would resemble a table whose values are passed in parameter attribute Values.
      /// </summary>
      /// <param name="rootNode"></param>
      /// <param name="nodeName"></param>
      /// <param name="attributeName"></param>
      /// <param name="attributeValues"></param>
      public static void CreateChildNodes( XmlNode rootNode, string nodeName, string attributeName, string[] attributeValues ) 
      { 
         XmlDocument doc = rootNode.OwnerDocument; 
         XmlNode newNode = null; 
         foreach ( string value in attributeValues ) 
         { 
            newNode = doc.CreateElement( nodeName ); 
            CreateAttribute( newNode, attributeName, value ); 
            rootNode.AppendChild( newNode ); 
         }
      }
        #endregion
        
      #region Creation of Multiple child nodes
      /// -----------------------------------------------------------------------------
      /// <summary>
      /// Converts a string array to XmlNodes and appends all those nodes to a root node.
      /// </summary>
      /// <param name="rootNode"></param>
      /// <param name="names"></param>
      /// <returns></returns>
      /// <remarks>
      /// </remarks>
      /// -----------------------------------------------------------------------------
      public static void CreateChildNodes( XmlNode rootNode, string[] names )
      { 
         XmlDocument doc = rootNode.OwnerDocument; 
         XmlNode newNode = null; 
         foreach ( string name in names ) 
         { 
            newNode = doc.CreateElement( name ); 
            rootNode.AppendChild( newNode ); 
         }
      }
}

Related Tutorials