CSharp examples for System.Xml:XML Attribute
Creates XML child nodes that would resemble a table whose values are passed in parameter attribute Values.
// All rights reserved. using System.Diagnostics; using System.Collections.Specialized; using System.Xml; using System.Data; using System;/*from w w w .j a va2 s . com*/ public class Main{ /// <summary> /// Creates child nodes that would resemble a table whose values are passed in parameter attributeValues. /// </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 ); } } }