DB: The guidelines for the database are not to important to generate the XML, as you can always get it out in a fashion you need, but the best design I could think of would be:
Table: People
person_id - auto-incrememnting id
person_name - text, varchar, char, etc
SQL to retrieve data:
"SELECT person_name FROM People"
XML: Now perhaps the easiest way to create the xml is to just create a large string. This is both more efficient than creatnig an XML DOM document on the fly and easier.
So say we execute out SQL statement and get a recordset back with an unknown number of records, to create the XML we could do the following:
'pretend rsPeople is our recordset
'insert the root element
Code:
xmlString = "<people>"
'make sure we are at the first record
'start our loop through the recordset
'each record should be encapsulated by a person element
Code:
xmlString = xmlString & "<person>"
'add the name element with record info
Code:
xmlString = xmlString & "<name>" & rsPeople("name") & "</name>"
'finish the person element before moving on
Code:
xmlString = xmlString & "</person>"
'incrememnt recordset to next record
'Finish the root element
Code:
xmlString = xmlString & "</people>"
Now at this point if you need to save the xml to a file there are a couple ways to handle it. You can either create a File object using the FileSystemObject to get a reference to the file and a TextStream object to write to the file, you could use ADO to get a reference to the file and open a TextStream for writing to the file, or you can use the XML DOM that I didn't use above.
I prefer using the XML Dom in this case because I am lazy:
'instantiate the object
Code:
Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
'load our xml string into the object
'save it out to a file in same directory
Code:
xmlObj.Save Server.MapPath("people.xml")
'Dereference object
And there we have it, data successfully pulled from a db and saved out as a valid xml document.
Hope this helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---