Click to return to the XML (Extensible Markup Language) home page    
IXMLDOMDocument::createEn...     IXMLDOMDocument::createPr...     IXMLDOMDocument Interface    
Web Workshop  |  XML (Extensible Markup Language)

IXMLDOMDocument::createNode Method


Creates a node using the supplied type, name, and namespace.

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMDocument.createNode(Type, name, namespaceURI)

C/C++ Syntax

HRESULT createNode(
    VARIANT Type,
    BSTR name,
    BSTR nameSpaceURI,
    IXMLDOMNode **node);

Parameters

Type
[in] Value that uniquely identifies the node type. This can be specified using either the integer value or the string value. For the complete list of values, see the DOMNodeType enumeration or the description for the name parameter.
name
[in] Value for the new node's nodeName property. The relationship between the node name and node type is summarized below.
nameSpaceURI
[in] Namespace unique resource indicator (URI). If specified, the node is created in the context of the nameSpaceURI parameter with the prefix specified on the node name. If the name parameter does not have a prefix, this is treated as the default namespace.
node
[out] Newly created node.

C/C++ Return Values

S_OK
Value returned if successful.
E_INVALIDARG
Value returned if node is null.
E_FAIL
Value returned if an error occurs.

Remarks

The name parameter depends on the value of the Type parameter, as follows:

NODE_ATTRIBUTE
The name of the attribute.
NODE_CDATA_SECTION,
NODE_COMMENT,
NODE_DOCUMENT,
NODE_DOCUMENT_FRAGMENT,
NODE_TEXT
The nodeName property for these node types is a constant value; the name parameter is ignored.
NODE_DOCUMENT_TYPE
The name of the document type—for example, the xxx in <!DOCTYPE xxx ...>.
NODE_ELEMENT
The name of the XML tag, with any namespace prefix included if present.
NODE_ENTITY
The name of the entity.
NODE_ENTITY_REFERENCE
The name of the entity referenced. Note that the name does not include the leading ampersand or the trailing semicolon. The name includes the namespace if one is present.
NODE_NOTATION
The name of the notation.
NODE_PROCESSING_INSTRUCTION
The target—the first token following the <? characters.

You cannot create a node of type NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, or NODE_NOTATION.

When a node is created, it is created in the context of a namespace if one is supplied (if the nameSpaceURI parameter is supplied). If one is not supplied, the node is created in the namespace of the document. If nameSpaceURI is specified, the node is created in the context of the nameSpaceURI with the prefix specified on the node name.

For node types that don't have names, the empty string, "", should be passed as the name parameter.

For elements and entity references, when the nameSpaceURI parameter is anything other than "" and the name parameter does not contain a prefix (xxx in xxx:yyy), the nameSpaceURI is treated as the default namespace.

Attributes cannot be scoped to a default namespace, and other elements are not qualified to a particular namespace (they are treated as being from the namespace defined by the document itself).

When nameSpaceURI is the empty string, the node is created within the special namespace of the current document.

Creating a qualified node without specifying a non-empty nameSpaceURI returns an error. That is, if the name parameter contains a colon character, which indicates that the node is being created in the context of a namespace, you must also supply the namespace prefix in the nameSpaceURI parameter.

This member is an extension of the W3C DOM.



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.