Greetings all. I'm using Windows 7 32, and am trying to add a node element to an existing and simple XML document. What I am trying to do is store a filename and a filepath as defaults for an FTP application I'm making. So, for example, if user needs to FTP a file called 'File1' to local directory 'filepath1' on a regular basis, they will simply choose the filename from a list (which is already working), and pick a default filepath from a list (which is also already working), and click a button to store the filename and file path in an XML document so the next time they need to FTP that file, they can simply click a button without having to choose the lcd every time. Using too many "how to" sites to list, I got the below to create the XML file if it does not already exist, but honestly, I don't know if this is the best way to accomplish what I need to do.
set objFSO = CreateObject("Scripting.FileSystemObject")
set xmlDoc = CreateObject("Microsoft.XMLDOM")
strFile = "u:\xml\default_mapping.xml"
If Not (objFSO.FileExists(strFile)) Then
set objRoot = xmlDoc.createElement("default_mapping")
xmlDoc.appendChild objRoot
set objFname = xmlDoc.createElement("FileName")
objRoot.appendChild objFname
objFname.text = "File1" 'this will be a variable passed by calling sub
objFname.setAttribute "SavePath", "filepath1" 'this will be a variable passed by calling sub
set objIntro = xmlDoc.createProcessingInstruction("xml","version='1.0'")
xmlDoc.insertBefore objIntro, xmlDoc.childNodes(0)
xmlDoc.Save strFile
Else
'Don't know what to do here to add another file
End if
Now, this all fires upon the user choosing the filename and filepath from two list boxes, which are passed as variables where here I have hard coded 'File1' and 'filepath1'. If the file does not exist, the above code creates XML file 'default_mapping.xml', which looks like this...
<?xml version="1.0"?>
<default_mapping><FileName SavePath="filepath1">File1</FileName></default_mapping>
My problem is that I need to be able to be able to add more elements when the user wants to store another file and filepath. I found lots of help with creating the file, but if I saw anything about adding elements, I did not know what I was looking at. I'm comfortable with VBScript, but XML is new, so I don't have a good grasp of terms describing XML. I *think* in the above example FileName is a child element of the default_mapping node, and SavePath is an attribute of that element. If the XML file already exists, I need to know how to add 'File2' and 'filepath2', and 3, ad infinitum. Does anyone know of a link that will describe how to do this? Thank you.
Greg