devxlogo

Using setAttribute Method of DOM Object in VB

Using setAttribute Method of DOM Object in VB

Question:

I am unable to use “setAttribute” method in Visual Basic. Following is the piece of code.

Dim objXML As DOMDocumentDim objOrders As IXMLDOMNodeDim objOrder As IXMLDOMNodeSet objXML = CreateObject("Microsoft.XMLDOM")Set objOrders = objXML.createElement("Orders")objXML.appendChild objOrdersSet objOrder = objXML.createElement("Order")objOrders.appendChild objOrderobjOrder.setAttribute "OrderID", rsOrderHeaders("OrderID")         

Please let me know where I am going wrong. Is there any other way to set the attribute for a node?

Answer:

When I initially looked at it, I thought the problem may be in the assignment from the recordset, but it suddenly hit me that your primary problem stems from the fact that you are declaring objOrders as an IXMLDOMNode. This interface doesn’t support setAttribute, although one of its children, IXMLDOMElement, does. What you should have said was:

Dim objXML As DOMDocumentDim objOrders As IXMLDOMElementDim objOrder As IXMLDOMElement

See also  5 Strategies for Supercharging Your CRM
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist