Document interface

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.

Example

Java

Document doc = docBuilder.newDocument();
Attr attr = doc.createAttribute("name");

VisualBasic

Dim xmlDoc As New Msxml2.DOMDocument30
Dim newAtt As IXMLDOMAttribute
Set newAtt = xmlDoc.createAttribute("name")

The example creates a document object and attribute object.


createAttribute() method

Java Syntax

Attr createAttribute(String name) throws DOMException
AttrThe returned Attr object.
nameThe name for the created attribute.

VisualBasic Syntax

Sub createAttribute(name, mode) Returns IXMLDOMAttribute
nameThe name for the created attribute.
modeThe read / write mode for the created attribute.
IXMLDOMAttributeThe returned Attr object.
After creation, the Attr instance can be set on an Element instance using the setAttributeNode method.