The Convert method creates an instance of the Formats object in NLS.dll. Once again, the code uses the CreateInstance function in MTSEnvironment.bas.
The GetIdField function is called and returns the name of the likely primary key. Identifying the Primary Key Field shows the code that identifies this field. The following line of code shows the call to the GetIdField function:
Set oIDField = GetIDField(oRs)
The following line of code shows the intial value of sRec. The DTD (see Creating a DTD on the Fly) specifies that an ID is required and the first element in the XML data stream must have this syntax and contain the value of the unique identifier for the record.
sRec = "<record id='_" & oIDField.value & "'> " & vbCrLf
The code loops through each field in the record and copies the value of the field to a variable (vValue), adds the begin element tag, and examines the type property of the field object. Copying the value makes the value available for repeated access. When the data type for a field is ntext, you can access the field value only once, because the field stores a pointer to the data rather than the data itself; you lose the pointer after you access the field the first time. The field types are adCurrency, adDate, adDBDate, adDBFileTime, adDBTime, adDBTimeStamp, adFileTime, adDecimal, adDouble, and adNumeric. The specified method in the Formats component is then called and returns the transformed value. In the following code, the call to FormatLocaleDateTime is for numeric data:
vValue = oField.value ' check for null value carefully, esp. nTEXT type
If Not (IsNull(vValue) Or vValue = "") Then
sRec = sRec & "<" & oField.name & ">"
Select Case oField.Type
Case adDate, adDBDate, adDBFileTime, adDBTime, adDBTimeStamp,adFileTime:
sRec = sRec & oNLS.FormatLocaleDateTime(0, vValue)
The HTMLEncode method applies HTML encoding to the content of the field.
sRec = sRec & oServer.HTMLEncode(vValue)
The following line of code appends the end tag for the element:
sRec = sRec & "</" & oField.name & ">" & vbCrLf
The following line of code appends the end tag for the record:
sRec = sRec & "</record>" & vbCrLf
The flushCount value, which is set in the EmitDTD method and described in Creating a DTD on the Fly, causes the Flush method to send the buffered output (approximately one record) to the browser immediately.
If oRs.RecordCount Mod flushCount = 0 Then oResponse.Flush