Function GetNodeWithText(xmlNode, ByVal strPath, strText, blnDuplicatePath) 'Returns the node that has the path and text value. 'Creates the node if it doesn't exist. xmlNode is a 'reference to the document or to a node in that document. 'Typical use: ' Set xml = CreateObject("Microsoft.XMLDOM") ' xml.async = False ' xml.load("C:\file.xml") ' Set node = xml.selectSingleNode("//root/environment") ' Set node = GetNodeWithText(node, "var/name", "REDIRECT_STATUS", True) ' Set node = GetNodeWithText(node.parentNode, "value", "200", False) 'Creates xml similar to the following ' ' ' ' SOME_NAME ' some_value ' ' ' REDIRECT_STATUS ' 200 ' ' ' Dim xml, nodes, node, parent, newNode '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 'Test to see if we have a node with the data On Error Resume Next Set nodes = Nothing Set nodes = xmlNode.selectNodes(strPath) On Error Goto 0 If Not(nodes Is Nothing) Then For Each node In nodes If node.Text = strText Then Set GetNodeWithText = node Exit Function End If Next End If 'The specified key/data node doesn't exist, so create it Set node = CreateNode(xmlNode, strPath, blnDuplicatePath) node.Text = strText Set GetNodeWithText = node End Function