Creates and returns a new node object that can be added to a DOM tree.
… xmldoc_object.CreateNode(type, name)
Prerequisites
None
Parameters
type
A required String expression that specifies the type of the node to be created. The String value must be one of those shown below in the Remarks section.
name
A String expression that specifies the name of the node to be created. The name is required for some node types and ignored for others. See the table below in the Remarks section.
Remarks
This method creates a new node for a DOM tree, but does not add it to the tree. The node type is specified by the type parameter as shown in Table 19-117.
Type String value | name parameter | Description |
---|---|---|
attribute |
Required |
An attribute. Normally has either a document or element as its parent. In XML data, attributes are embedded inside the element name start tag. For example an attribute named color of element sample appears as <sample color="value"> |
cdatasection |
Ignored |
A CDATA text node permits special characters in its data section without requiring that they be encoded. The data starts with “<!CDATA[” and ends with “]]>” |
comment |
Ignored |
A special text node that contains a comment not considered part of the document data. The comment data begins with “<?--“ and ends with “-->”. |
element |
Required |
The basic node type. An element corresponds to an XML tag that begins with “<”. For example the element named sample begins with “<sample>” and ends with “</sample>” |
processinginstruction |
Required |
A special text node that contains processor-specific information. The information data begins with "<?" and ends with "?>". |
text |
Ignored |
The data contents of an element or attribute. It holds whatever is between two element tags or the “value” of an attribute. |
To be meaningful, the new node must be added to the tree using one of the XmlNode methods: AppendChild, InsertAfter, InsertBefore,or ReplaceChild.
For most applications, it is easier to build a tree by using the XmlNode methods (AddElement, AddElementNode and AddAttribute) rather than using CreateNode.
Examples
Dim doc As XmlDoc
Dim root As XmlNode
Dim elem As XmlNode
Dim text As XmlNode
doc = New XmlDoc("my_doc")
root = doc.DocumentElement
elem = doc.CreateNode("element", "section1")
text = doc.CreateNode("text")
text.value = "This is the data for section 1"
elem.AppendChild(text)
root.AppendChild(elem)
See Also
XML Classes | xmlnode_object.AddAttribute | xmlnode_object.AddElement | xmlnode_object.AddElementNode