Function CreateNode(ByVal xmlNode, ByVal strPath, blnMakeDuplicate) 'Creates any depth of path under the starting node. Returns the final node. Dim xml, newNode, strNode 'Get a ref to the root If xmlNode.ownerDocument Is Nothing Then Set xml = xmlNode Else Set xml = xmlNode.ownerDocument End If 'Clean the path up Do While Left(strPath, 1) = "/" : strPath = Mid(strPath, 2) : Loop Do While Right(strPath, 1) = "/" : strPath = Left(strPath, Len(strPath) - 1) : Loop 'Check each element in the path to see if it exists For Each strNode In Split(strPath, "/") Set newNode = Nothing On Error Resume Next Set newNode = xmlNode.selectSingleNode(strNode) On Error Goto 0 If newNode Is Nothing Then 'The desired node doesn't exist -- Create it Set newNode = xml.createElement(strNode) Set xmlNode = xmlNode.appendChild(newNode) Else If blnMakeDuplicate = True Then 'Create a duplicate node with the same name Set newNode = xml.createElement(strNode) Set xmlNode = xmlNode.appendChild(newNode) Else 'Point xmlNode to the existing node without creating a duplicate Set xmlNode = newNode End If End If Next 'Return Set CreateNode = xmlNode End Function