Here it is fully functional, based on an example cursor and dummy entries ... The critical function is the DumpXML () routine and needs the alias of the file to be reset, the size of the file you want to close it on (in the size of "k") and the prefix the name of the file you want to flush XML. It will automatically generate an ex sequence: MyXMLOutput1.xml, MyXMLOutput2.xml, MyXMLOutput3.xml, etc., For many cases when necessary. Took me about 15 minutes.
CREATE CURSOR SomeTest ; ( SomeField1 c(10),; AnotherField i,; SomeNumber N(8,2),; MemoFld m,; SomeDateTime t; ) INSERT INTO SomeTest VALUES ( "testchar10", 9403, 12345.78, "some memo value string", DATETIME() ) DumpXML( ALIAS(), 300, "MyXML" ) FUNCTION dumpXML LPARAMETERS cAliasName, nSizeLimit, cNameOfXMLOutput IF NOT USED( cAliasName ) RETURN "" ENDIF */ Assume size limit in "k" nSizeLimit = nSizeLimit * 1024 SELECT ( cAliasName ) */ Get a copy of the structure without disrupting original USE IN SELECT( "MySample" ) && pre-close in case left open from prior cycle SELECT * ; FROM ( cAliasName ) ; WHERE RECNO() = 1; INTO CURSOR MySample READWRITE SELECT MySample */ Populate each field with maximum capacities... typically */ critical for your char based fields AFIELDS( aActualStru ) cMemoFields = "" lHasMemoFields = .f. FOR I = 1 TO FCOUNT() cFieldName = FIELD(I) DO CASE CASE aActualStru[i,2] = "C" replace &cFieldName WITH REPLICATE( "X", aActualStru[i,3] ) CASE aActualStru[i,2] = "L" replace &cFieldName WITH .T. CASE aActualStru[i,2] = "D" replace &cFieldName WITH DATE() CASE aActualStru[i,2] = "T" replace &cFieldName WITH DATETIME() CASE aActualStru[i,2] = "M" */ Default memo as a single character to ensure */ closing field name </endoffield> included in XML replace &cFieldName WITH "X" */ if a MEMO field, add this element to a string */ to be macro'd to detect its size... Each record */ can contain MORE than one memo field... */ Ex: + LEN( ALLTRIM( MemoFld )) lHasMemoFields = .T. cMemoFields = cMemoFields + " + len( ALLTRIM( " + cFieldName + " ))" CASE aActualStru[i,2] = "I" */ Integer, force to just 10 1's replace &cFieldName WITH 1111111111 CASE aActualStru[i,2] = "N" */ Actual numeric and not an integer, double or float */ Allow for full length plus decimal positions NumValue = VAL( REPLICATE( "9", aActualStru[i,3] - aActualStru[i,4] - 1 ); + "." + REPLICATE( "9", aActualStru[i,4] )) replace &cFieldName WITH NumValue ENDCASE ENDFOR */ Strip leading " + " from the string in case multiple fields IF lHasMemoFields cMemoFields = SUBSTR( cMemoFields, 3 ) ENDIF cXML = "" LOCAL oXML as XMLAdapter oXML = CREATEOBJECT( "XMLAdapter" ) oXML.AddTableSchema( "MySample" ) oXML.ToXML( "cXML", "", .f. ) */ Now, determine the size of the per record at its full length