The ViewRecords method calls EmitDTD (a method in the SQLXML component), which creates a Document Type Definition (DTD) for the XML stream. EmitDTD receives two parameters: the recordset oRS, which ViewRecords creates and populates, and oResponse, which is an ASP Response object. Within EmitDTD, code runs to assemble a string (sRec) that contains a DTD for the current recordset. This code can emit a DTD for any recordset.
The following four steps create and emit a DTD:
sRec = "<!DOCTYPE xmldata [" & vbCrLf & vbCrLf & _
"<!ELEMENT xmldata (record)+>" & vbCrLf & _
"<!ELEMENT record ("
sSep = ""
For Each oField In oRs.Fields
sRec = sRec & sSep & oField.name
If oField.Attributes And adFldIsNullable Then
sRec = sRec & "?"
End If
sSep = ","
Next
sRec = sRec & ")>" & vbCrLf
For Each oField In oRs.Fields
sRec = sRec & "<!ELEMENT " & oField.name & " (#PCDATA)>" & vbCrLf
…
Next
sRec = sRec & vbCrLf & _
"<!ATTLIST record" & vbCrLf & _
" id ID #REQUIRED" & vbCrLf & _
" >" & vbCrLf & vbCrLf & _
"]>" & vbCrLf & vbCrLf
The following code calculates the delay before data is written to the browser based on the approximate size of the record. The flushCount variable is a private variable that contains the value of the delay.
flushCount = CInt(4096 / recSize) + 1