IXMLDOMNode.insertBefore (C#)
Previous | Next |
IXMLDOMNode.insertBefore (C#)
The insertBefore method inserts a child node before the specified node or at the end of the list.
Syntax
IXMLDOMNode = IXMLDOMNode .insertBefore( object objnewChild, object objrefChild );
Parameters
objnewChild
[in] object containing the address of the new node to be inserted.
objrefChild
[in] object 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 objrefChild must be a child node of this node or NULL. The objnewChild is inserted before objrefChild in the child list. If objrefChild is NULL, objnewChild is inserted at the end of the child list. If objrefChild 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.
using Microsoft.WindowsMediaServices.Interop; using interop_msxml; // Declare variables. WMSServer Server; IXMLDOMDocument Playlist; IXMLDOMElement Root; IXMLDOMNode newNode; IXMLDOMNode currNode; try { // Create a new WMSServer object. Server = new WMSServerClass(); // Create a new playlist object. Playlist = Server.CreatePlaylist(); // Load a playlist. Playlist.load("file://c:\\wmpub\\wmroot\\simple.wsx"); // Retrieve the root element. Root = Playlist.documentElement; // Create a new node and insert it before the second child node // of the root element. newNode = Playlist.createNode(DOMNodeType.NODE_ELEMENT, "seq", ""); currNode = Root.insertBefore(newNode, Root.childNodes[1]); } catch (Exception e) { // TODO: Handle exceptions. }
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 |