Share via


IXMLDOMNode.insertBefore (Visual Basic .NET)

banner art

Previous Next

IXMLDOMNode.insertBefore (Visual Basic .NET)

The insertBefore method inserts a child node before the specified node or at the end of the list.

Syntax

  IXMLDOMNode = IXMLDOMNode
  .insertBefore(
  objnewChild As Object,
  varrefChild As Variant
)

Parameters

objnewChild

[in] Object containing the address of the new node to be inserted.

varrefChild

[in] Variant containing the address of the reference node. If this parameter is NULL, objnewChild is inserted at the end of the child list.

Return Values

When getting the value, this method returns the child node that was successfully inserted.

Remarks

When inserting a new child node into a list of existing nodes, 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 Inserts objnewChild and returns objnewChild.

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
Inserts objnewChild and returns objnewChild.
NODE_ELEMENT Inserts objnewChild and returns objnewChild. 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 Inserts objnewChild and returns objnewChild.

The node supplied in varrefChild must be a child node of this node or NULL. The objnewChild is inserted before varrefChild in the child list. If varrefChild is NULL, objnewChild is inserted at the end of the child list. If varrefChild is not a child of this node, an error is returned.

Example Code

The following example creates a new IXMLDOMNode object and inserts it before the second child of the top-level node.

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 newNode As IXMLDOMNode
Dim currNode As IXMLDOMNode

' 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 node and insert it before the second child node
' of the root element.
Set newNode = Playlist.createNode(NODE_ELEMENT, "seq", "")
Set currNode = root.insertBefore(newNode, root.childNodes.Item(1))
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