Share via


IXMLDOMNode.replaceChild (Visual Basic .NET)

banner art

Previous Next

IXMLDOMNode.replaceChild (Visual Basic .NET)

The replaceChild method replaces the specified old child node with the supplied new child node.

Syntax

  IXMLDOMNode = IXMLDOMNode
  .replaceChild(
  objnewChild As Object,
  objoldChild As Object
)

Parameters

objnewChild

[in] Object containing the address of the new child that is to replace the old child. If NULL, objoldChild is removed without a replacement.

objoldChild

[in] Object containing the address of the old child that is to be replaced by the new child.

Return Values

When getting the value, this method returns the old child node that is replaced by the new child node.

Remarks

When replacing an old child node with a new child node, the new child must be a valid child type for the existing parent node. The following tables list which child node types are valid and not valid for the parent node types specified.

The following table lists possible child node types for the parent node type NODE_ATTRIBUTE.

Child node type Description
NODE_ATTRIBUTE
NODE_COMMENT
NODE_ELEMENT
Not valid. Returns an error. These node types cannot be children of an attribute.
NODE_PROCESSING_INSTRUCTION Not valid. Returns an error. This node type either cannot be a child of an attribute node or it is read-only.
NODE_TEXT Replaces the specified objoldChild with the supplied objnewChild and returns objoldChild.

The following table lists possible child node types for the parent node type NODE_DOCUMENT.

Child node type Description
NODE_ATTRIBUTE
NODE_DOCUMENT
NODE_TEXT
Not valid. Returns an error. These nodes cannot be children of a document node.
NODE_COMMENT
NODE_PROCESSING_INSTRUCTION
Replaces the specified objoldChild with the supplied objnewChild and returns objoldChild.
NODE_ELEMENT Replaces objoldChild with objnewChild and returns objoldChild. By definition, an XML document (the document node) can have only a single child element. Therefore, an error is returned if the document node already has a child element.

The following table lists possible child node types for the parent node type NODE_ELEMENT.

Child node type Description
NODE_ATTRIBUTE
NODE_DOCUMENT
Not valid. Returns an error. These node types cannot be children of an element node.
NODE_COMMENT
NODE_ELEMENT
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
Replaces the specified objoldChild with objnewChild and returns objoldChild.

Example Code

The following example creates a new IXMLDOMNode object, newElem, and replaces the specified child node with newElem.

Imports interop_msxml
Imports Microsoft.WindowsMediaServices.Interop

On Error GoTo Err

' Declare variables.
Dim Server As New WMSServerClass()
Dim Playlist As IXMLDOMDocument
Dim root As IXMLDOMElement
Dim newElem As IXMLDOMElement

' Create a new playlist object.
Set Playlist = Server.CreatePlaylist

' Load a playlist.
Playlist.Load ("file://c:\wmpub\wmroot\simple.wsx")

' Retrieve the root element.
Set root = Playlist.documentElement

' Create a new element.
Set newElem = Playlist.createElement("seq")

' Replace the child of the current node with
' the newly created node.
root.childNodes.Item(1).replaceChild newElem, root.childNodes.Item(1).childNodes.Item(0)
Exit Sub

Err:
' TODO: Handle errors.

Requirements

Reference: Add references to Microsoft.WindowsMediaServices and interop_msxml.

Namespace: Microsoft.WindowsMediaServices.Interop, interop_msxml.

Assembly: Microsoft.WindowsMediaServices.dll, interop_msxml.dll.

Library: WMSServerTypeLib.dll, msxml.dll.

Platform: Windows Server 2003 family, Windows Server 2008 family.

See Also

Previous Next