Append element : XmlElement « XML « C# / C Sharp

Append element

 * FCKeditor - The text editor for Internet -
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *  - GNU General Public License Version 2 or later (the "GPL")
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 * == END LICENSE ==
 * Useful tools for XML.

using System ;
using System.Globalization ;
using System.Xml ;

namespace FredCK.FCKeditorV2
  internal sealed class XmlUtil
    private XmlUtil()

    public static XmlNode AppendElement( XmlNode node, string newElementName )
      return AppendElement( node, newElementName, null ) ;

    public static XmlNode AppendElement( XmlNode node, string newElementName, string innerValue )
      XmlNode oNode ;

          //  BP.PubClass.WinOpen

      if ( node is XmlDocument )
                oNode = node.AppendChild( ((XmlDocument)node).CreateElement( newElementName ) ) ;
        oNode = node.AppendChild( node.OwnerDocument.CreateElement( newElementName ) ) ;

      if ( innerValue != null )
        oNode.AppendChild( node.OwnerDocument.CreateTextNode( innerValue ) ) ;

      return oNode ;

    public static XmlAttribute CreateAttribute( XmlDocument xmlDocument, string name, string value )
      XmlAttribute oAtt = xmlDocument.CreateAttribute( name ) ;
      oAtt.Value = value ;
      return oAtt ;

    public static void SetAttribute( XmlNode node, string attributeName, string attributeValue )
      if ( node.Attributes[ attributeName ] != null )
        node.Attributes[ attributeName ].Value = attributeValue ;
        node.Attributes.Append( CreateAttribute( node.OwnerDocument, attributeName, attributeValue ) ) ;


Related examples in the same category

1.Gets an XmlAttributeCollection containing the list of attributes
2.Creates a duplicate of this node.
3.Returns the value for the attribute with the specified name.
4.Returns the XmlAttribute with the specified name.
5.Returns an XmlNodeList containing a list of all descendant elements that match the Name.
6.Gets a boolean value indicating whether the current node has any attributes.
7.Gets or sets the concatenated values of the node and all its children.Gets or sets the concatenated values of the node and all its children.
8.Gets or sets the tag format of the element.
9.Gets the local name of the current node.
10.Gets the qualified name of the node.
11.Gets the XmlDocument to which this node belongs.
12.Removes all specified attributes and children of the current node. Default attributes are not removed.
13.Removes all specified attributes from the element.
14.Removes an attribute by name.
15.Removes an attribute with the specified local name and namespace URI.
16.Removes the attribute node with the specified index from the element.
17.Removes the XmlAttribute specified by the local name and namespace URI.
18.Adds the specified XmlAttribute.
19.Saves all the children of the node to the specified XmlWriter.
20.Saves the current node to the specified XmlWriter.
21.Load Xml String
22.Creates the element.
23.Get first child and its Node List
24.Appends a new empty element to the given target element.
25.Appends a new element containing a text value to the given target element.