System.Xml.XmlDocument.CreateNode Method

Creates an System.Xml.XmlNode with the specified node type, XmlDocument.Name, and XmlNode.NamespaceURI.

Syntax

public virtual XmlNode CreateNode (string nodeTypeString, string name, string namespaceURI)

Parameters

nodeTypeString
String version of the System.Xml.XmlNodeType of the new node. This parameter must be one of the values listed in the table below.
name
The qualified name of the new node. If the name contains a colon, it is parsed into XmlNode.Prefix and XmlDocument.LocalName components.
namespaceURI
The namespace URI of the new node.

Returns

The new XmlNode.

Remarks

The nodeTypeString parameter is case sensitive and must be one of the values in the following table.

attribute

Attribute

cdatasection

CDATA

comment

Comment

document

Document

documentfragment

DocumentFragment

documenttype

DocumentType

element

Element

entityreference

EntityReference

processinginstruction

ProcessingInstruction

significantwhitespace

SignificantWhitespace

text

Text

whitespace

Whitespace

Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.

The following table shows you what NodeType[row] is allowed inside another NodeType[column] according to the W3C Extensible Markup Language (XML) 1.0 recommendation (www.w3.org/TR/1998/REC-xml-19980210).

Document

no

no

no

no

no

no

no

no

no

DocumentType

yes

no

no

no

no

no

no

no

no

XmlDeclaration

yes*

no

no

no

no

no

no

no

no

Element

yes

no

no

yes

no

no

no

no

yes***

Attribute

no

no

no

yes****

no

no

no

no

no

Text

no

no

no

yes

yes

no

no

no

yes

CDATA

no

no

no

yes

no

no

no

no

yes***

Markup**

yes

no

no

yes

no

no

no

no

no

EntityReference

no

no

no

yes

yes

no

no

no

yes

* The XmlDeclaration node must be the first child of the Document node.

** Markup includes ProcessingInstruction and Comment nodes.

*** Element and CDATA nodes are only allowed in EntityReference nodes when the EntityReference node is not a child of an Attribute node.

**** Attributes are not children of an Element node. Attributes are contained inside an attribute collection that belongs to an Element node.

This method is a Microsoft extension to the Document Object Model (DOM).

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0