XmlDocument.CreateNode Method (XmlNodeType, String, String, String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a XmlNode with the specified XmlNodeType, Prefix, Name, and NamespaceURI.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

abstract CreateNode : 
        type:XmlNodeType *
        prefix:string *
        name:string *
        namespaceURI:string -> XmlNode
override CreateNode : 
        type:XmlNodeType *
        prefix:string *
        name:string *
        namespaceURI:string -> XmlNode

Parameters

type
Type: System.Xml.XmlNodeType

The XmlNodeType of the new node.

prefix
Type: System.String

The prefix of the new node.

name
Type: System.String

The local name of the new node.

namespaceURI
Type: System.String

The namespace URI of the new node.

Return Value

Type: System.Xml.XmlNode

The new XmlNode.

Exception Condition
ArgumentException

The name was not provided and the XmlNodeType requires a name.

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

DocumentType

XmlDeclaration

Element

Attribute

Text

CDATA

Markup

EntityReference

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 the Element node.

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

The following example adds a new element to the document.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: