BizTalk Utilities CV ,   Jobs ,   Code library  
 
 

Microsoft DOM Objects Reference

Download ReferenceDownload this Reference 

Previous PageTable Of ContentsIndexNext Page

createNode()

Is a member of:

DOMDocument

Syntax

As an alternative to the createElement(), createAttribute(), etc. methods, you can also use the createNode() method, which creates any type of Node, using the following syntax:

set objXMLDOMNode = objDOMDocument.createNode(Type, name, namespaceURI)

Table  describes the syntax of createNode().

0.0.1 Signature of the createNode method (continued)

Type
Specify the type of Node, which can be the numeric value of the nodeType or a string of the nodeTypeString.
name
Specify the name of the Node or, if there is no name, then an empty string (""). Remember that if you're dealing with an ele ment or an entity reference, the name is case-sensitive.
namespaceURI
Specify the namespace or, if there is no namespaceURI, then an empty string ("").

Remark

Before we continue, please refer to the nodeType property section, which explains in detail the different Node types, their enumeration values, and descriptions.

You cannot create a Node of the following types:

      ¬ Document-it is the root of the XML; it cannot be a childNode. The
      create-Node() method only creates child Nodes. To create the root
      of your XML, you initialize a DOMDocument object as we have seen
      in most examples so far.

      ¬ Document type-DTDs cannot be added to the DOMDocument. See the
      docType property in this section.

      ¬ Entity-entities are declared in the DTD; therefore, being external to the XML file restricts their creation

      ¬ Notation-this is the same as entities

If you attempt to create any of the above, an error will occur.

Table  lists what to insert in the Type and Name parts of the create- Node() signature. We have not added the namespace property in the signature, as this only applies to element and attribute Nodes, where you can specify the namespace. If there is not a namespace, you need to add an empty string (""), as this signature has no optional addresses.

In the Type part of the createNode() signature, you can insert either the nodeType value or the nodeTypeString value. You can insert the Name section in the name part of the signature.

0.0.1 Specifications of values to insert in createNode signature (continued)

Type of Node
node Type value
nodeType
String value
name
Element
1
"element"
tagName/nodeName (e.g., "PERSON")
Attribute
2
"attribute"
name of the attribute/nodeName (e.g., "PERSONID")
Text
3
"text"
empty string ("")
CDATA section
4
"cdatasection"
empty string ("")
Entity Reference
5
"entityreference"
name of the referenced entity/nodeName (e.g., "USA")
Processing Instruction
7
"processinginstruction"
target/nodeName ("realaudio')
Comment
8
"comment"
empty string ("")
Document Fragment
11
"documentfragment"
empty string ("")

    Example

In the following examples, we create the different nodeTypes and append them to the documentElement property of the DOMDocument.

To create an element Node, pass the nodeTypeString as the type:

Set objNode = m_objXMLDOM.createNode("element", "PERSON", "")

m_objXMLDOM.documentElement.appendChild objNode

      ¬ It is such a pity that the DOM- NodeType enum for the Node type in the signature was not used as the passed variable. (Instead, an integer or string was inserted.) It would have made the Intellisense auto-complete in VB so much easier to read.

Alternatively, you can pass the nodeType enumeration as the type:

Set objNode = m_objXMLDOM.createNode(NODE_ELEMENT, "PERSON", "")

m_objXMLDOM.documentElement.appendChild objNode

Otherwise, you can pass the nodeType enumeration value as the type:

Set objNode = m_objXMLDOM.createNode(1, "PERSON", "")

m_objXMLDOM.documentElement.appendChild objNode

The example from the createComment() method example would change as follows for the createNode() method:

Dim objDOMDocument As DOMDocument

Dim objComment As IXMLDOMComment

Set objDOMDocument = New DOMDocument

Set objComment = objDOMDocument.createNode(NODE_COMMENT, "", "")

objComment.Text = "This is a comment."

objDOMDocument.appendChild objComment

      ¬ We've used the nodeType enumuration for the nodeType. Don't forget to pass empty strings for the other two parameters, as they are not optional.

      ¬ Add the comment text.

      ¬ Append the comment Node to its parent, which in this case is the DOMDocument.

Previous PageTable Of ContentsIndexNext Page

This manuscript is an abridged version of a chapter from the Manning Publications book XML Programming with VB and ASP. This chapter looks at the Microsoft DOM objects. NOTE: Most images have been removed to increase speed and many of the code comments have also been removed for presentation. Please purchase the book to enjoy the full experience of all the chapters with images and code comments!

 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)



Information Online

swimming pool contractor
chicago web site design
halloween masks
Web Hosting
help desk support
Christian Dior sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP