XML & VFP

60
CURSORTOXML( ) (Función) Visual Studio .NET 2003 Convierte un cursor Visual FoxPro en texto XML. CursorToXML(nWorkArea | cTableAlias, cOutput [, nOutputFormat [, nFlags [, nRecords [, cSchemaName [, cSchemaLocation [, cNameSpace ]]]]]]) Devuelve Numérico. EL número de bytes escrito en el archivo o variable de memoria. Parámetros nWorkArea Especifica el área de trabajo de la tabla a partir de la cual se crea la cadena XML. Si se especifica 0 o nada, Visual FoxPro utiliza el área de trabajo actual. cTableAlias Especifica el alias de la tabla a partir de la cual se crea la cadena XML. cOutput La ruta y el nombre del archivo o el nombre de la variable de memoria a los que se envían los resultados. Si nFlags se establece para el resultado de la variable de memoria (el valor predeterminado), se devuelve el XML a la variable de memoria. Si la variable de memoria no existe, se creará. Si nFlags se establece para el resultado del archivo (512), y el archivo no existe, éste se creará. Si el archivo ya existe, se sobrescribirá. Se respeta la configuración de SAFETY. nOutputFormat Especifica el formato de los resultados de la cadena XML, según la tabla siguiente: nOuputFormat Descripción 1 – ELEMENTS XML centrado en elementos (valor predeterminado) 2 – ATTRIBUTES XML centrado en atributos 3 – RAW Genérico, XML centrado en atributos nFlags

Transcript of XML & VFP

CURSORTOXML( ) (Función)Visual Studio .NET 2003

Convierte un cursor Visual FoxPro en texto XML.

CursorToXML(nWorkArea | cTableAlias, cOutput [, nOutputFormat [, nFlags [, nRecords [, cSchemaName [, cSchemaLocation [, cNameSpace ]]]]]])

Devuelve

Numérico. EL número de bytes escrito en el archivo o variable de memoria.

Parámetros

nWorkAreaEspecifica el área de trabajo de la tabla a partir de la cual se crea la cadena XML. Si se especifica 0 o nada, Visual FoxPro utiliza el área de trabajo actual.

cTableAliasEspecifica el alias de la tabla a partir de la cual se crea la cadena XML.

cOutputLa ruta y el nombre del archivo o el nombre de la variable de memoria a los que se envían los resultados. Si nFlags se establece para el resultado de la variable de memoria (el valor predeterminado), se devuelve el XML a la variable de memoria. Si la variable de memoria no existe, se creará. Si nFlags se establece para el resultado del archivo (512), y el archivo no existe, éste se creará. Si el archivo ya existe, se sobrescribirá. Se respeta la configuración de SAFETY.

nOutputFormatEspecifica el formato de los resultados de la cadena XML, según la tabla siguiente:

nOuputFormat Descripción

1 – ELEMENTS XML centrado en elementos (valor predeterminado)

2 – ATTRIBUTES XML centrado en atributos

3 – RAW Genérico, XML centrado en atributos

nFlagsEspecifica el tipo de esquema XML que se produce según la tabla siguiente:

nFlag Bit Descripción del resultado

0 0000 XML con formato UTF-8 (valor predeterminado)

1 0001 XML sin formato (cadena continua)

2 0010 Se escriben elementos vacíos, con elementos de apertura y de cierre (por ejemplo, <cc04><cc04/>).

4 0100 Conserva los espacios en blanco de los campos.

8 1000 Ajusta campos Memo en secciones CDATA.

16 10000 Codificación de resultados

32 100000 Codificación de resultados

512 1000000000 cOutput es un nombre de archivo. El valor predeterminado denFlag, 0, crea una variable de memoria.

Nota   Cuando la codificación de resultados es UTF-8 (la predeterminada), la Declaración XML no contiene el atributo Encoding= (ningún atributo de codificación = UTF-8).

Cuando la codificación de resultados predeterminada se establece en la Página de códigos del cursor o de la tabla, el atributo de codificación se escribe de acuerdo con la tabla siguiente.

Nota   Los indicadores de codificación se establecen mediante la combinación de los bits 4 y 5 (0010000).

Indicador de codificación

Bits 4 y 5 Descripción

+0 00 Windows 1252 (predeterminado)

+16 01 El atributo de codificación de los resultados se establece en la página de códigos del cursor.

+32 10 El atributo de codificación de los resultados se establece en UTF-8, sin conversión de caracteres.

+48 11 El atributo de codificación de los resultados se establece en UTF-8; los caracteres de doble byte se traducen a UTF-8.

La tabla siguiente muestra una lista de páginas de código comunes compatibles con Windows.

Página de códigos

Plataforma Atributo de codificación en la declaración XML

Comentarios

932 Windows japonés shift-jis  

949 Windows coreano iso-2022-kr –o bien–ks_c_5601-1987

950 Windows chino (Taiwan) big5  

1250 Windows de Europa del Este

Windows-1250 tenga en cuenta mayúsculas y minúsculas

1251 Windows ruso Windows-1251  

1252 Windows de EE.UU. y Europa Occidental

Windows-1252  

1253 Windows griego Windows-1253  

1254 Windows turco Windows-1254  

1255 Windows hebreo Windows-1255  

1256 Windows árabe Windows-1256  

437 MS-DOS WINDOWS-1252  

850 MS-DOS, Int Windows-1252  

866 MS-DOS, Ruso Windows-1251  

865 MS-DOS, Nórdico Windows-1252  

Nota   Cuando se utiliza una codificación basada en páginas de códigos(juegos de caracteres tradicionales de byte único o doble byte de Visual FoxPro), tales como Windows-1252 (código de página 1252) o Big5 (código de página 950), no es necesaria ninguna otra traducción de caracteres para una presentación correcta en Internet Explorer.Nota   Cuando la codificación de los resultados se establece en UTF-8, el resultado establecido puede someterse opcionalmente a una traducción de caracteres al formato UTF-8. Cuando no hay atributo de codificación, se asume que el XML es UTF-8, por lo que no es necesario (pero podría ser deseable) agregar el atributo de codificación UTF-8.

Generalmente, para XML: si hay una marca de orden de byte, el formato es Unicode (LE o BE, según BOM). Si no hay etiqueta de codificación, el formato es UTF-8. Cuando se establece la codificación de resultados en UTF-8 (la opción predeterminada), el conjunto de resultados debe someterse a una traducción de caracteres al formato UTF-8. Cuando no hay atributo de codificación, se asume

que el XML es UTF-8, por lo que no es necesario (pero podría ser deseable) agregar el atributo de codificación UTF-8.

nRecordsEspecifica el número de registros que se convertirán en resultados XML. Si nRecords es 0 (la opción predeterminada), en los resultados se incluyen todos los registros. Si nRecords es mayor que el número de registros que quedan en la tabla, se incluyen todos los registros restantes.

cSchemaNameEspecifica el nombre y la ubicación de la información de esquema para los datos de cFileName.

cSchemaName Descripción

"" Especifica que no se producirá ningún esquema.

"1" Especifica que se producirá un esquema en línea.

<cSchemaName> Especifica el nombre y la ruta del archivo externo que contendrá el esquema (que tiene como alcance el elemento raíz del XML).

Si cSchemaName contiene un nombre de archivo, y no se proporciona el parámetro cSchemaLocation o se deja en blanco, el contenido de cSchemaName se escribe en el atributo xsi:schemaLocation o xsi:noNamespaceSchemaLocation en el XML.

En el código siguiente, Visual FoxPro genera un archivo XML genérico, myxmlfile.xml, a partir de labels.dbf del alias "Labels" y el archivo de esquema mySchema, en la misma carpeta.

CursorToXML("LABELS", "myXMLFile.xml", 1, 512, 0, "mySchema.xsd")

Si se especifica "", en lugar de "mySchema", no se produce ningún esquema; si se especifica "1", como en el ejemplo siguiente, se produce un esquema en línea:

CursorToXML("LABELS", "myXMLFile.xml", 1, 512, 0, "1")cSchemaLocation

Especifica una ubicación opcional donde la aplicación que lee los datos XML debería buscar el archivo de esquema. El contenido de cSchemaLocation se escribe en el atributo xsi:schemaLocation o xsi:noNamespaceSchemaLocation de los datos XML producidos. Utilice este parámetro sólo cuando esté desplegando el esquema en una ubicación distinta a la de los datos XML. cSchemaLocation puede ser una dirección http u otra URL. Deberá copiar el archivo de esquema en la ubicación que especificó encSchemaLocation.

Por ejemplo:

CursorToXML("LABELS", "myXMLFile.xml", 1, 512, 0, ; "mySchema.xsd", "http://www.microsoft.com/mySchema.xsd")

producirá datos XML que contienen el atributo siguiente:

xsi:noNamespaceSchemaLocation=" http://www.microsoft.com/mySchema.xsd"

Si cSchemaName está en blanco, especificar cSchemaLocation hará que se escriban los mismos atributos en los datos XML. Esto le permite señalar a un esquema existente sin recrear el esquema cada vez que se llama a CursorToXML.

cNamespaceEspecifica el nombre del archivo xml o el esquema que se va a producir. La cadena vacía, "", es el valor predeterminado.

Si no se especifica el parámetro cNamespace y el esquema es externo, en el esquema no se escribe ninguna declaración de espacio de nombres. Si no se especifica ningún parámetro cNamespace y el esquema está en línea, el valor de targetNamespace en el esquema se establece en "", la cadena vacía.

Si se especifica cNameSpace, el atributo targetNamespace se establece en el mismo valor y se agrega al esquema el atributo elementFormDefault="qualified".

Observaciones

El resultado de CursorToXML( ) se adhiere al orden de índice del cursor, SET FIELDS TO, y a las configuraciones de filtro actuales. Esta función no conserva la ubicación del cursor. Después de la llamada, el puntero del registro del cursor informa de EOF si todos los registros se incluyeron ya en los resultados o apuntará al último registro de los resultados de XML si no se incluyeron aún todos los registros.

Si cSchemaName incluye una URL, el esquema se escribe en el directorio actual; debe cargarse en el servidor para permitir el acceso al explorador o el analizador. Los esquemas externos se escriben siempre en la misma ubicación que el archivo XML.

Cuando se utilizan conjuntos de caracteres de un solo byte, la codificación predeterminada, Windows-1252, no necesita ninguna traducción más de caracteres para mostrarse correctamente en Internet Explorer. Tanto Unicode como UTF-8 necesitan que el conjunto de resultados se someta a una traducción de caracteres al formato adecuado y, si se especificó que los resultados se guarden en un archivo, que se escriba en el archivo la BOM (Byte Order Mark) correspondiente Unicode o UTF-8, para designar el tipo de archivo como Unicode o UTF-8.

XMLUPDATEGRAM( ) FunctionVisual Studio 2005Other Versions

This topic has not yet been rated Rate this topicMirrors changes made in a buffered table or cursor in an XML UpdateGram and returns a character string that contains the UpdateGram.

An XML UpdateGram represents the before and after conditions of the changed portion of a Visual FoxPro table or cursor. Through additional processes, you can use an UpdateGram to commit these changes to the data represented by the XML UpdateGram document.

NoteTo use XMLUPDATEGRAM( ), you must use SET MULTILOCKS ON and enable table buffering.

TipBefore calling XMLUPDATEGRAM( ), you should specify the key field list by calling CURSORSETPROP( ) with the KeyFieldList property against existing cursors and tables. If you do not specify key fields, both the before and after representations contains all the fields in the table. If you specify one or more key fields, only those fields appear in the before section.

XMLUPDATEGRAM( [ cAliasList [, nFlags [, cSchemaLocation]]])

Parameters

cAliasListSpecifies a comma-separated list of open tables or cursors, listed either by name or work area numbers in any combination, to include in the XML UpdateGram. If you specify no value or an empty string ("") forcAliasList, Visual FoxPro uses all open tables and cursors in the current data session that contain buffered changes.

nFlagsSpecifies whether to return a formatted file. The following table lists the additive flags for nFlags.nFlag Bit Output description

0 0000 (Default) Use UTF-8 formatted XML.

1 0001 Use unformatted, for example, continuous string XML.

2 0010 Enclose empty elements with both open and closing elements, for

example, <cc04><cc04/>.

4 0100 Preserve white space in fields.

8 1000 Wrap Memo fields in CDATA sections.

16 10000 Output encoding.

32 100000 Output encoding.

32768 none Indicates that a code page should be used.

NoteWhen output encoding is UTF-8 (default), the XML Declaration does not contain an Encoding= attribute (no encoding attribute = UTF-8).

When output encoding is set to default to the code page of the cursor or table, the encoding attribute will be written according to the following table.

NoteEncoding flags are set by combining bits 4 and 5 (0010000).

Encoding flag

Bits 4 and 5

Description

+0 00 (Default) Windows 1252

+16 01 Set output encoding attribute to the code page of the cursor.

+32 10 Set output encoding attribute to UTF-8 (no character translation).

+48 11 Set output encoding attribute to UTF-8 and translate double-byte characters to UTF-8.

cSchemaLocation

Specifies the name and location of the mapping schema, if it exists.

NoteYou must supply the mapping schema.

For example, suppose you pass the a schema called mySchema.xsd to cSchemaLocation, the UpdateGram created contains a mapping schema attirbute as it appears in the following XML:

<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="mySchema.xsd" > <updg:before>

Return Value

Character data type. XMLUPDATEGRAM( ) returns a character string that contains the XML UpdateGram.

Remarks

You can use XMLUPDATEGRAM( ) with the OLE DB Provider for Visual FoxPro. However, the_VFP VFPXMLProgID property is not supported because the _VFP system variable is not supported in the OLD EB Provider.

NoteTo use the Visual FoxPro OLE DB Provider with XMLUPDATEGRAM( ), you must install MSXML 3.0 on the computer with the OLE DB Provider.

SQL Server and Visual Studio support the DiffGram format for updating XML. However, SQL XML requires a mapping schema to support this format. Therefore, XMLUPDATEGRAM( ) does not support this format.

To avoid possible errors generated by XMLUPDATEGRAM( ) on tables containing Memo or General fields, use the CURSORSETPROP( ) function. The following example shows how to include memo data in an XML UpdateGram by setting the KeyFieldList property using CURSORSETPROP( ):

SET MULTILOCKS ONCREATE CURSOR Test (mField M, cField I AUTOINC)INSERT INTO Test (mField) VALUES ("123456789")INSERT INTO Test (mField) VALUES ("23456789")INSERT INTO Test (mField) VALUES ("3456789")INSERT INTO Test (mField) VALUES ("456789")CURSORSETPROP("Buffering",5)CURSORSETPROP("keyfieldlist",'cField')UPDATE Test SET mField = "XXXXXXX" WHERE cField < 3STRTOFILE(XMLUPDATEGRAM(),'xmlupdate.txt')MODIFY FILE xmlupdate.txtRETURN

To write memo data in the XML UpdateGram to SQL Server, you must use an explicit schema on the SQL Server and reference the schema in the XML UpdateGram.

Unlike the CURSORTOXML( ) function, XMLUPDATEGRAM( ) disregards SET FIELDS statements and reads from the underlying cursor directly. To change the table structure before calling XMLUPDATEGRAM( ), you must copy the data into a new cursor. For example, to change a Numeric field to a Currency field, the following example uses a SQL SELECT statement to create a new cursor and uses that cursor

with XMLUPDATEGRAM( ). The example makes the Total_Price field a currency field, enables buffering with CURSORSETPROP( ), adds sales tax with the REPLACE command, and creates an XML UpdateGram using the XMLUPDATEGRAM( ) function.

SELECT OrderID, CustID, NTOM(Total_Price) as Total_Price; FROM Orders INTO CURSOR New_Orders READWRITE CURSORSETPROP("Buffering", 5, "New_Orders") REPLACE Total_Price WITH (Total_Price * 1.083) cXMLUpdg = XMLUPDATEGRAM("New_Orders")

When using flag 32768, the flag's 16 and 32 settings can affect which code page is applied depending on the type of data you are writing to XML. The following tables show the possible combinations of settings and the code page each combination applies.

For XML documents written with the 32768 flag set, the following code pages are applied.

Flag 16

Flag 32

Flag 32768 is Set

Not set

Not set

XML documents: Window-1252.

Unicode data: code page 1252.

Character data: default code page, unless a field is marked as NOCPTRANS.

True (.T)

Not set

XML documents: Plus-CodePage property of the cursor. If XMLField CodePage property is greater than zero (0) and it doesn’t match the cursor’s code page, an error is reported.

Unicode data: the Code page property of the cursor object.

Character data: none. Raw data from the Visual FoxPro tables (.dbf) are used instead.

Not set

Set XML documents: UTF-8 code page.

Unicode data: UTF-8 code page.

Character data: Default code page unless field is marked as NOCPTRANS, in which case no additional character translation to UTF-8 occurs.

Set Set XML documents: UTF-8 code page.

Unicode data: UTF-8 code page.

Character data: default code page unless a field is marked as NOCPTRANS, in which case the data are translated to UTF-8 using

the SYS(3005) setting.

For XML documents written without setting the 32768 flag, the following code pages are applied.

Flag 16

Flag 32

Without the 32768 flag

Not set

Not set

XML documents: Window-1252.

Unicode data: code page 1252.

Character data: default code page unless a field is marked as NOCPTRANS.

True (.T)

Not set

XML documents: CodePage property of the cursor.

Character data: none. Raw data from the Visual FoxPro tables (.dbf) are used instead.

Unicode data: code page property of the cursor object.

Not set

Set XML documents: UTF-8 code page.

Unicode data: UTF-8 code page.

Character data: default code page unless field is marked as NOCPTRANS, in which case no additional character translation to UTF-8 occurs.

Set Set XML documents: UTF-8 code page.

Unicode data: UTF-8 code page.

Character data: default code page unless field is marked as NOCPTRANS, in which case, they are translated to UTF-8 using code page for the current SYS(3005) setting.

XMLTOCURSOR( ) FunctionVisual Studio 2005Converts XML text into a Visual FoxPro cursor or table.

XMLTOCURSOR(eExpression | cXMLFile [, cCursorName [, nFlags ]])

Parameters

eExpression

Specifies the XML text or an expression that evaluates to valid XML data. The eExpression parameter can be a Visual FoxPro memory variable, memo field contents, the return from an HTTP request, the return result from a SOAP method call, XML from the XMLDOM, or an ADO stream.

NoteXMLTOCURSOR( ) generates an error if eExpression is not found or if eExpression does not parse to valid XML.

cXMLFile

Specifies the name, and, optionally, the path of a physical XML file that resides on your local computer or network.

If you do not specify a path, Visual FoxPro searches the path along the Visual FoxPro directory for the XML file.

cCursorName

Specifies the name of the cursor to store the result and creates the cursor in the current work area.

If the cursor name already exists or is open, Visual FoxPro closes the cursor and creates a new one in an unused work area. If you omit or pass an empty string ("") for cCursorName, Visual FoxPro creates a cursor named "XMLRESULT" for returning the result.If cCursorName contains data and nFlags is set to 8192, Visual FoxPro appends the data being imported from the XML file to the existing table or cursor. The table or cursor must be open or in use. IfcCursorName is an empty string (""), Visual FoxPro imports XML into the table or cursor that is open in the current work area.

nFlagsSpecifies how XMLSource eExpression is handled in XMLTOCURSOR( ). The following table describes the values for nFlags.nFlags Bit Description

0 0000 (Default) Treats the first parameter as a string containing XML data.

4 0100 Preserves white space in data and overrides the xml:space attribute of the XML data.

512 01000000000 Specifies that the first parameter, either an eExpression or a cXMLFile, is a string containing the name and path of an XML data file.

1024 10000000000 NOCPTRANS – Creates Character and Memo fields in the resultant cursor with the NOCPTRANS option and inserts the text or XML values in the incoming elements into the Character or Memo field on an untranslated, byte-for-

byte basis.

When used with flag 1024, XMLTOCURSOR( ) returns a string padded with trailing spaces equal to the actual string, that is, a string twice the length.

2048 100000000000 Use when the imported schema has an XML schema definition (XSD) schema containing decimal data type with restrictions, or facets, of totalDigits="19" and fractionDigits="4."

XSD data type values are mapped to the Visual FoxPro Currency data type in the resulting cursor.

4096 1000000000000    Disables base64 decoding.

In Visual FoxPro, base64 encoding is intended for encoding only binary data.

8192 1100000000 Specifies that cCursorName is the name or alias of an existing table or cursor and imports the data from the specified XML file into an existing table or predefined cursor.If cCursorName contains data, the data imported from the XML file is appended to the existing data. If cCursorName is an empty string (""), the data from the XML file is imported into the table or cursor in the current work area.Setting nFlags to 8192 can be useful when an XML schema is not available or not practical for use.

32768 0x8000 Indicates that a code page should be used.

65536 0x10000 Maps XML Char fields to native Fox Varchar fields. If not specified, XML Char fields are mapped to Fox Character fields.

131072

0x20000 Maps XML base64Binary fields to native Fox Varbinary fields if less than 255 bytes or Blob fields if greater than this length. If not specified, XML base64Binary fields are mapped to Fox Memo fields.

When you use flag 8192, be aware of the following:

You must make sure the table schema matches the incoming XML elements in the appropriate manner. Visual FoxPro enforces the data types in cCursorName as described in the Data Type Matching table in this

topic but makes no other assumptions about data types. Attempting to import incompatible values generates the appropriate message.

If the XML contains or references a schema, and the data types in the schema conflict with the data types of the cursor or table, the data types in the cursor or table are used.

Element names in the XML file are mapped to the column names in cCursorName. In addition, Visual FoxPro imports only data from the element names in the XML file that match the column names in cCusorName.

The cursor or table can have fewer columns than those in the XML file, but it must have at least one matching column. The cursor or table can have additional columns that do not correspond to an element in the XML file.

If the table contains autoincrementing fields, XMLTOCURSOR( ) fails if AUTOINCERROR is set to ON. Setting AUTOINCERROR to OFF or turning off autoincrementing in the target table by usingCURSORSETPROP( ) allows XMLTOCURSOR( ) to succeed. The target table's autoincrementing field or fields are incremented according to the values specified, and the values in the source table are not copied.

The following table describes data type matching restrictions when setting nFlags to 8192.

Visual FoxPro data type Behavior

Character, Character(Binary), Memo,Memo (Binary)

Accepts any data but truncates any data exceeding the length of a Character column.

Currency Accepts numeric data within accepted range of the Currency type but truncates numbers outside this range.

Date Accepts XML format date and dateTime values.

Visual FoxPro converts the XML date and dateTime formats to the corresponding Visual FoxPro date. Visual FoxPro preserves only the M/D/Y portion of the XML date or dateTime value.

DateTime Accepts XML format date and dateTime values.

Visual FoxPro converts the XML

date and dateTime formats to the corresponding Visual FoxPro date and discards precision beyond the extent supported by Visual FoxPro.

Double Accepts numeric data within the accepted range of the Double type but truncates numbers outside this range.

Integer Accepts integer data within the accepted range of the Integer type but truncates numbers outside this range.

Logical Accepts the values True, .T., 1, False, .F., and 0.

Numeric, Float Accepts numeric data with or without decimals but truncates numbers outside the accepted range for these types according to Visual FoxPro rules or replaces with the numeric overflow indicator ("*************").

Return Value

Numeric data type. XMLTOCURSOR( ) returns the number of records created.

Remarks

You can use XMLTOCURSOR( ) with the OLE DB Provider for Visual FoxPro. However, the _VFP VFPXMLProgIDproperty is not supported because the _VFP system variable is not supported in the OLE DB Provider.

NoteTo use the Visual FoxPro OLE DB Provider with XMLTOCURSOR( ), you must install MSXML 3.0 on the computer with the OLE DB Provider.

XMLTOCURSOR( ) generates a syntax error for record lengths greater than approximately 160 columns. The exact number of columns that cause an error depends on the length of the column names.

XMLTOCURSOR( ) does not use the Varchar type when creating a cursor from an XML document. However,XMLTOCURSOR( ) supports appending data into an existing cursor with Varchar fields.

When calling XMLTOCURSOR( ) in append mode, Visual FoxPro adds an empty row if no XML element name matches any table or cursor column.

XMLTOCURSOR( ) converts Decimal data type to Numeric 20,19 (width, precision). In versions prior to Visual FoxPro 8.0, Decimal mapped to Numeric 8,0.

Numeric Overflow Conditions   XMLTOCURSOR( ) imports XML data containing Visual FoxPro numeric overflow conditions, for example, "*******", in place of a numeric or integer value. If a schema is provided, Visual FoxPro creates the correct data type in the resulting cursor but changes the overflow from asterisk (*) characters to 0.0 or 0 values. Therefore, the XML parser used by XMLTOCURSOR( ) does not throw an error as a result of character values stored in a decimal type element.

For more information about converting XML to Visual FoxPro data, see Converting Between XML and Visual FoxPro Data.

Converting Between XML and Visual FoxPro Data0 out of 1 rated this helpful Rate this topicVisual Studio 2005You can exchange data more easily with other applications by converting Visual FoxPro data to XML format. Visual FoxPro includes the following functions so you can convert data between XML and Visual FoxPro format:

CURSORTOXML( ) Function XMLTOCURSOR( ) Function

XMLUPDATEGRAM( ) Function

NoteYou must have the Microsoft XML Core Services (MSXML) parser installed before you can use the Visual FoxPro XML functions.

The following sections discuss considerations when converting between XML and Visual FoxPro data:

Processing XML Data in Variables or Strings Instead of Files XML String Conversion

Importing and Exporting XML Using Schemas

You can override the internal functionality of the CURSORTOXML( ), XMLTOCURSOR( ), andXMLUPDATEGRAM( ) functions by referencing a COM component using the VFPXMLProgID property. For more information, see VFPXMLProgID Property.

Visual FoxPro supports hierarchically formatted XML for XML DiffGram and .NET Framework ADO.NET DataSet formats by providing the XMLAdapter, XMLTable, and XMLField classes. For more information, see XML Functionality Using XMLAdapters.

Processing XML Data in Variables or Strings Instead of Files

XMLTOCURSOR( ) processes data differently from a variable or string than from a file. When converting XML to a cursor, the method used to pass XML to the function affects how double-byte character sets (DBCS) characters in the XML are handled. DBCS characters are interpreted correctly when using a file for XMLSource. However, if you need to use a memory variable or string, you can force interpretation to DBCS by using the following code inXMLTOCURSOR( ):

STRCONV(string,11)

The following example opens the Visual FoxPro sample Customer table located in the Visual FoxPro ..\Samples\Data\ directory and converts the data in the Customer table and saves the data in the table to a memory variable, lcXML, as XML:

CLEARCLOSE DATABASES ALLUSE HOME()+'samples\data\customer'CURSORTOXML('customer','lcXML',1,48,5,"","","")

The following line inserts incorrect characters in the resulting cursor:

XMLTOCURSOR(lcXML,"curCustomerList",4)

The following line uses the STRCONV( ) function and converts the XML to DBCS data correctly, opens a browse window for the table:

XMLTOCURSOR(STRCONV(lcXML,11),"curCustomerList",4) BROWSE

XML String Conversion

XMLTOCURSOR( ) does not perform automatic conversions of XML strings, for example, from ANSI to UTF-8. This might occur when reading an XML string from a file. To perform a conversion, use the STRCONV( ) function.

The following example demonstrates the parse error that occurs when Visual FoxPro encounters the first ASCII character:

CLOSE DATABASE ALLUSE HOME(2)+"\data\customer"CURSORTOXML("customer","lcXML",1,32)STRTOFILE(lcXML,"customer.xml")XMLTOCURSOR("customer.xml","curCustomer",512)RETURN

You can prevent the parse error generated by converting the string to UTF-8 when the XML is written or when it is written to the file. The following example converts the string to UTF-8 as it is being written to the file by using theSTRCONV( ) function with the STRTOFILE( ) function:

CLOSE DATABASE ALLUSE HOME(2)+"\data\customer"CURSORTOXML("customer","lcXML",1,32)STRTOFILE(STRCONV(lcXML,9),"customer.xml")XMLTOCURSOR("customer.xml","curCustomer",512)RETURN

In the example, you can use a value of 48 for the nFlag parameter in the STRCONV( ) function to create the XML encoded as UTF-8. However, this does not work for XML provided from an external source or with XML that is not generated with the CURSORTOXML( ) function.

For more information, see STRCONV( ) Function.

Importing and Exporting XML Using Schemas

When you import XML using the XMLTOCURSOR( ) function, Visual FoxPro uses an external or internal schema, if available, to determine the cursor or table structure before making a single pass to convert the data. When no schema is provided, Visual FoxPro makes two passes through the XML data: the first pass determines the data structure in the best possible way and the second to perform the conversion. The XML must generally conform to a format that can be interpreted as a table in addition to being well-formed. Well-formed XML that is not easily deconstructed into a table format will fail to import.

The following is an example of XSD schema generated by the Visual FoxPro CURSORTOXML( ) function:

<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?><xsd:schema id="VFPSchema" targetNamespace="http://microsoft.com" xmlns="http://microsoft.com" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified"> <xsd:element name="atxm"> <xsd:complexType> <xsd:all> <xsd:element name="ikey" minOccurs="0" type="xsd:int"/> <xsd:element name="nc00" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:decimal"> <xsd:precision value="10"/> <xsd:scale value="4"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="mc03" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="2147483647"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="cc04" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="128"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="lc05" minOccurs="0" type="xsd:boolean"/> <xsd:element name="fc06" minOccurs="0" type="xsd:double"/> <xsd:element name="yc07" minOccurs="0" type="xsd:decimal"/> <xsd:element name="ic08" minOccurs="0" type="xsd:int"/> <xsd:element name="bc09" minOccurs="0" type="xsd:double"/> <xsd:element name="dc10" minOccurs="0" type="xsd:date"/>

<xsd:element name="tc11" minOccurs="0" type="xsd:timeInstant"/> <xsd:element name="ts12" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:binary"> <xsd:encoding value="base64"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:all> </xsd:complexType> </xsd:element> <xsd:element name="VFPData" msdata:lsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="atxm"/> </xsd:choice> </xsd:complexType> </xsd:element></xsd:schema>

Currently, Visual FoxPro exports XML in the following formats:

Element-centric   Each field in a resulting or source cursor or table is represented by a sub-element of the top-level element.

<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?> <!-- Note targetNamespace in root (VfpData) element. If set to

default (""), xmlns attrib is not written --> <VfpData xmlns="http://www.microsoft.com"> <alltypesxm> <ikey>2</ikey> <nc00>1.1111</nc00> <mc03>H1111111111111111111</mc03> <cc04>H111111111111111111</cc04> <lc05>true</lc05> <fc06>-1111000</fc06> <yc07>-111111111.1111</yc07> <ic08>-11111111</ic08> <bc09>-111111111111.1</bc09> <dc10>1999-03-02T08:00:00</dc10> <tc11>1999-03-02T09:01:01</tc11> <ts12>AAAAAAAAAr8=</ts12> </alltypesxm> </VfpData> Attribute-centric   The cursor is identified by the keyword "VFPData" and each

field in a resulting or source cursor or table is represented by an attribute of the VFPData element.

<?xml version="1.0" encoding="Windows-1252" ?> <!-- Note targetNamespace in root element --> <VFPData xmlns="http://www.microsoft.com"> <atxm_attr ikey="2" nc00="12345.1111" mc03="H1111111111111111111" cc04="H111111111111111111"

lc05="1" fc06="-1111000.0000" yc07="-111111111.1111" ic08="-11111111"

bc09="-111111111111.100000" dc10="1999-03-02" tc11="1999-03-02T01:01:01" ts12="AAAAAAAAAr0=" /> <atxm_attr ikey="3" nc00="2.1111" mc03="H2222222222222222222" cc04="H222222222222222222" lc05="1" fc06="22220000.0000" yc07="2222222222.2222" ic08="222222222" bc09="222222222222.2200000" tc11="2000-10-03T02:02:02" ts12="AAAAAAAAAr8=" /> </VFPData> Raw   Each row in a resulting or source cursor or table is represented by an XML

element with the generic identifier "row", and each column value is mapped to an attribute of the row element where the attribute name is equal to the column name. This format is identical to Attribute-centric except for "row" as the name of the top-level element.

<?xml version="1.0"?> <!-- Note no targetNamespace in root element --> <VFPData> <row CustomerID="CACTU" CompanyName="Cactus Comidas para llevar" ContactName="Patricio Simpson" ContactTitle="Sales Agent" Address="Cerrito 333" City="Buenos Aires" PostalCode="1010" Country="Argentina" Phone="(1) 135-5555" Fax="(1) 135-4892"/>

</VFPData>

Visual FoxPro and XML Schema Data Type Mapping2 out of 2 rated this helpful Rate this topicVisual Studio 2005The following tables describe the following default data type mappings between Visual FoxPro and XML schema data types:

XML Schema Primitive Data Types to Visual FoxPro Data Types XML Schema Derived Types to Visual FoxPro Data Types

Visual FoxPro Data Types to XML Schema Definition (XSD) Data Types

XML Schema Definition (XSD) Data Types to Visual FoxPro Data Types

XML Data Reduced (XDR) Schema Data Types to Visual FoxPro Data Types

XML Schema Primitive Data Types to Visual FoxPro Data Types

XML data type

Facets Description Visual FoxPro data type

anyURI length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents a Uniform Resource Identifier (URI) as defined by RFC 2396. An anyURI value can be absolute or relative and might have an optional fragment identifier.

Memo. Visual FoxPro applies a hyperlink to a URI in a Memo.

base64Binary

length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents base64-encoded arbitrary binary data. A base64Binary is the set of finite-length sequences of binary octets.

Memo (Binary), Varbinary or Blob

boolean pattern, whiteSpace Represents Boolean values, which are either true or false.

Logical

date enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a calendar date. The pattern for date is CCYY-MM-DD with an optional time zone indicator as allowed for dateTime.

Date

dateTime enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a specific instance of time.

The pattern for dateTime is CCYY-MM-DDThh:mm:ss where CC represents the century, YY the year, MM the month, and DD the day, preceded by an optional leading negative (-) character to indicate a negative number. If the negative character is omitted, positive (+) is assumed. The T is the date/time separator and hh, mm, and ss represent hour, minute, and second respectively. Additional digits can be used to increase the precision of fractional seconds if desired. For example, the format ss.ss... with any number of digits after the decimal point is supported. The fractional seconds part is optional.

This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC) or to indicate the time zone. For example, the difference between the local time and Coordinated Universal Time, immediately followed by a sign, + or -, followed by the difference from UTC represented as hh:mm (minutes is required). If the time zone is included, both hours and minutes must be present.

DateTime

decimal enumeration, pattern, totalDigits, fractionDigits, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents arbitrary precision numbers.

Numeric, Currency, or Character

double pattern, Represents double-precision 64-bit Double

enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

floating-point numbers.

duration enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents duration of time. The pattern for duration is PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, T the date/time separator, nH the number of hours, nM the number of minutes, and nS the number of seconds.

For example, to indicate a duration of 1 year, 2 months, 3 days, 10 hours, and 30 minutes, you write: P1Y2M3DT10H30M. You could also indicate a duration of minus 120 days as -P120D.

Character (C(30))

float pattern, enumeration, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents single-precision 32-bit floating-point numbers.

Double

gDay enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a Gregorian day that recurs, specifically a day of the month, such as the fifth day of the month. A gDay is the space of a set of calendar dates. Specifically, it is a set of one-day long, monthly periodic instances.

The pattern for gDay is --DD with an optional time zone indicator as allowed for date.

Character (C(10))

gMonth enumeration, pattern,

Represents a Gregorian month that recurs every year. A gMonth is the

Character (C(10))

minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

space of a set of calendar months. Specifically, it is a set of one-month long, yearly periodic instances.

The pattern for gMonth is -MM- with an optional time zone indicator as allowed for date.

gMonthDay enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a specific Gregorian date that recurs, specifically a day of the year, such as the third of May. A gMonthDay is the set of calendar dates. Specifically, it is a set of one-day long, annually periodic instances.

The pattern for gMonthDay is --MM-DD with an optional time zone indicator as allowed for date.

Character (C(10))

gYear enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a Gregorian year. A set of one month-long, nonperiodic instances.

The pattern for gYear is CCYY with an optional time zone indicator as allowed for dateTime.

Character (C(15))

gYearMonth enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents a specific Gregorian month in a specific Gregorian year. A set of one month-long, nonperiodic instances.

The pattern for gYearMonth is CCYY-MM with an optional time zone indicator.

Character (C(15))

hexBinary length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents arbitrary hex-encoded binary data. A hexBinary is the set of finite-length sequences of binary octets. Each binary octet is encoded as a character tuple, consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code.

Memo (Binary)

NOTATION length, Represents a NOTATION attribute Memo

enumeration, pattern, maxLength, minLength, whiteSpace

type. A set of QNames.

QName length, enumeration, pattern, maxLength, minLength, whiteSpace

Represents a qualified name. A qualified name is composed of a prefix and a local name separated by a colon. Both the prefix and local names must be an NCName. The prefix must be associated with a namespace Uniform Resource Identifier (URI) reference, using a namespace declaration.

Memo

string length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents character strings. Character when maxLength is specified and less than 255 characters. Otherwise, Memo.

time enumeration, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, whiteSpace

Represents an instance of time that recurs every day.

The pattern for time is hh:mm:ss.sss with an optional time zone indicator.

Character (C(20))

XML Schema Derived Types to Visual FoxPro Data Types

XML data type Facets Description Visual FoxPro data type

byte enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits,

Represents an integer with a minimum value of -128 and maximum of 127. This data type is derived from short.

Integer

whiteSpace

ENTITIES length, maxLength, minLength, enumeration, whiteSpace

Represents the ENTITIES attribute type and contains a set of values of type ENTITY.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

ENTITY length, enumeration, pattern, maxLength, minLength, whiteSpace

Represents the ENTITY attribute type in XML 1.0 Recommendation. This is a reference to an unparsed entity with a name that matches the specified name. An ENTITY must be an NCName and must be declared in the schema as an unparsed entity name. This data type is derived from NCName.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

ID length, enumeration, pattern, maxLength, minLength, whiteSpace

Represents the ID attribute type defined in the XML 1.0 Recommendation. The ID must be a no-colon-name (NCName) and must be unique within an XML document. This data type is derived from NCName.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

IDREF length, enumeration, pattern, maxLength, minLength, whiteSpace

Represents a reference to an element that has an ID attribute that matches the specified ID. An IDREF must be an NCName and must be a value of an element or attribute of type ID within the XML document. This data type is derived from NCName.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

IDREFS length, maxLength, minLength, enumeration, whiteSpace

Represents the IDREFS attribute type and contains a set of values of type IDREF.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

int enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum value of -2147483648 and maximum of 2147483647. This data type is derived from long.

Integer

integer enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents a sequence of decimal digits with an optional leading sign (+ or -). This data type is derived from decimal.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

language length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents natural language identifiers (defined by RFC 1766). This data type is derived from token.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

long enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum value of -9223372036854775808 and maximum of 9223372036854775807. This data type is derived from integer.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

Name length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents names in XML. A Name is a token that begins with a letter, underscore, or colon and continues with name characters (letters, digits, and other characters). This data type is derived from token.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

NCName length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents noncolonized names. This data type is the same as Name, except it cannot begin with a colon. This data type is derived from Name.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

negativeInteger enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer that is less than zero and consists of a negative sign (-) and sequence of decimal digits. This data type is derived from nonPositiveInteger.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

NMTOKEN length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents the NMTOKEN attribute type. An NMTOKEN is set of name characters, such as letters, digits, and other characters, in any combination. Unlike Name and NCName, NMTOKEN has no restrictions on the starting character. This data type is derived from token.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

NMTOKENS length, maxLength, minLength, enumeration, whiteSpace

Represents the NMTOKENS attribute type and contains a set of values of type NMTOKEN.

Memo

nonNegativeInteger

enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer that is greater than or equal to zero. This data type is derived from integer.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

nonPositiveInteger enumeration, Represents an integer that is less Integer, if

fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

than or equal to zero and A nonPositiveInteger consists of a negative sign (-) and sequence of decimal digits. This data type is derived from integer.

totalDigits is less than 10. Otherwise, Character with totalDigits respected.

normalizedString length, pattern, maxLength, minLength, enumeration, whiteSpace

Represents white space normalized strings. This data type is derived from string.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

positiveInteger enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer that is greater than zero. This data type is derived from nonNegativeInteger.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

token enumeration, pattern, length, minLength, maxLength, whiteSpace

Represents tokenized strings. This data type is derived from normalizedString.

Character, if maxLength is specified and less than 255. Otherwise, Memo.

short enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum value of -32768 and maximum of 32767. This data type is derived from int.

Integer

unsignedByte enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum of zero and maximum of 255. This data type is derived from unsignedShort.

Integer

unsignedInt enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum of zero and maximum of 4294967295. This data type is derived from unsignedLong.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

unsignedLong enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum of zero and maximum of 18446744073709551615. This data type is derived from nonNegativeInteger.

Integer, if totalDigits is less than 10. Otherwise, Character with totalDigits respected.

unsignedShort enumeration, fractionDigits, pattern, minInclusive, minExclusive, maxInclusive, maxExclusive, totalDigits, whiteSpace

Represents an integer with a minimum of zero and maximum of 65535. This data type is derived from unsignedInt.

Integer

Visual FoxPro Data Types to XML Schema Definition (XSD) Data Types

Visual FoxPro data type

XSD data type and examples

Restrictions and sample restriction

Comments

Blob xs:base64Binary <xs:element name="ts12" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:base64Binary"/>

</xs:simpleType>

</xs:element>

Content is translated to base64 encoding.

Maps to SQL Binary.

Character xs:string

Confirm this is electric

<xs:element name="cc04" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:maxLength value="128"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

 

Character (Binary)

xs:string

Confirm this is electric

<xs:element name="cc04" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:maxLength value="128"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

 

Currency xs:decimal

-1.23, 0, 123, 4, 1000.00

<xs:element name="yc07" minOccurs="0">

<xs:simpleType>

Currency is always 19,4.

<xs:restriction base="xs:decimal">

<xs:totalDigits value="19"/>

<xs:fractionDigits value="4"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

Date xs:date

1999-05-31

None  

DateTime xs:dateTime

1999-05-31T13:20:00.000-05:00

None  

Double xs:double

-INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN

None The export value should include the maximum scale allowed for double and not be limited to display scale (internal value of double).

Float xs:decimal <xs:element name="fc06" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:decimal">

<xs:totalDigits value="14"/>

<xs:fractionDigits value="4"/>

</xs:restriction>

totalDigits is the number of digits not including decimal point.

</xs:simpleType>

</xs:element>

General Not supported    

Integer xs:int

-1, 126789675

   

Logical xs:boolean

true, false, 1, 0

  Values are either true and false or 1 and 0.

Memo xs:string <xs:element name="mc03" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:maxLength value="2147483647"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

 

Memo (Binary)

xs:base64Binary <xs:element name="ts12" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:base64Binary"/>

</xs:simpleType>

</xs:element>

Content is translated to base64 encoding.

Maps to SQL Binary.

Numeric xs:decimal

-1.23, 0, 123, 1000.00

<xs:element name="nc00" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:decimal">

totalDigits is the number of digits not including decimal point.

<xs:totalDigits value="10"/>

<xs:fractionDigits value="4"/>

</xs:restriction>

</xs:simpleType>

</xs:element >

Varbinary xs:base64Binary <xs:element name="cc04" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:base64Binary">

<xs:maxLength value="128"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

Content is translated to base64 encoding.

Varchar xs:string

Confirm this is electric

<xs:element name="cc04" minOccurs="0">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:maxLength value="128"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

 

Varchar (Binary)

xs:string

Confirm this is electric

<xs:element name="cc04" minOccurs="0">

<xs:simpleType>

 

<xs:restriction base="xs:string">

<xs:maxLength value="128"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

XML Schema Definition (XSD) Data Types to Visual FoxPro Data Types

XSD data type Visual FoxPro data type

xsd:binaryBase64 Memo (Binary)

xsd:boolean Logical

xsd:date Date

xsd:dateTime DateTime

xsd:decimal Numeric

xsd:double Double

xsd:int Integer

xsd:string Character

xsd:string (more than 254 characters in length) Memo

XML Data Reduced (XDR) Schema Data Types to Visual FoxPro Data Types

XDR data type

Description Visual FoxPro data type

XSD type

bin.base64 Specifies MIME-style Base64-encoded binary data.

Memo (Binary)

base64Binary

bin.hex Specifies hexadecimal-encoded binary data.

Memo (Binary)

hexBinary

boolean Specifies a Boolean value of either 0 or 1. Logical boolean

Example: 0 is false and 1 is true.

char Specifies a number corresponding to the Unicode representation of a single character.

None Not supported

date Specifies the date in a subset of the ISO 8601 format without the time data.

Example: "1994-11-05"

Date date

dateTime Specifies a date in a subset of the ISO 8601 format with optional time and no optional zone. Fractional seconds can be as precise as nanoseconds.

Example: "1988-04-07T18:39:09"

DateTime dateTime

dateTime.tz Specifies a date in a subset of the ISO 8601 format with optional time and optional zone. Fractional seconds can be as precise as nanoseconds.

Example: "1988-04-07T18:39:09-08:00"

None None

entity Specifies a reference to an unparsed entity, requiring a matching <!ENTITY> declaration for each instance of the entity.

None None

entities Specifies a list of entities delimited by white space.

None None

enumeration Similar to nmtoken but with an explicit list of allowed values. Supported on attributes only.

Example: "Red Blue Green"

None None

fixed.14.4 Specifies a number with no more than fourteen digits to the left of the decimal point and no more than four to the right of the decimal point.

Example: 9999.0044

Currency decimal 19,4

float Specifies a real floating point number. Double double

Examples: 111, 3.14, -123.456E+10

i1 Specifies a 1-byte integer with an optional sign ranging from -128 to 127.

Examples: 1, 127, -128

Integer byte

i2 Specifies a 2-byte integer with optional sign ranging from -32768 to 32767.

Examples: 1, 703, -32768

Integer short

i4 Specifies a 4-byte integer with optional sign ranging from -2147483648 to 2147483647

Examples: 1, 703, -32768, 148343, -1000000000

Integer int

i8 Specifies an 8-byte integer with optional sign ranging from -9223372036854775808 to 9223372036854775807.

Examples: 1, 703, -32768, 1483433434334, -1000000000000000

Character or Integer

long

id Specifies a value that identifies an attribute as an id type attribute. The id values must be unique throughout the document.

In a document, idref(s) attributes refer to an id type attribute, forming a relationship similar to primary key and foreign key in relational databases.

Example: Cust1

None None

idref Specifies a value corresponding to an id type, enabling intra-document links.

Example: Cust1

None None

idrefs Similar to idref, except it contains multiple id type values separated by white space.

Example: Cust1 Cust2 Cust3

None None

int Specifies a signed integer.

Examples 11123, -123

Integer int

nmtoken Contains values that conform to the rules of the name token.

Example: Cust1

None None

nmtokens Similar to nmtoken except it can have a list of nmtoken values separated by white space.

Example: Cust1 Cust2 Cust3

None None

notation A NOTATION type None None

number A number with no limits on the digits

Examples: 111, 3.14, -123.456E+10

NoteFor ADO RecordSets, a special case exists where the number might have Currency type. When dt:type='number'in an ADO XDR Schema, Visual FoxPro checks for the existence of rs:dbtype='currency'.

Character, Currency, or Numeric as appropriate

decimal

r4 Same as float but only 4-byte encoding. Value ranges from 1.17549435E-38F to 3.40282347E+38F.

Double float

r8 Specifies a floating point number. This data type supports only 15 digits of precision and value ranges from 2.2250738585072014E-308 to 1.7976931348623157E+308.

Double double

string Specifies a string.

Example: "This is a string"

Character, if maxLength is less than 255. Otherwise, Memo.

string

time Specifies a time in a subset of the ISO 8601 format with no date and no time zone.

Example: "08:15:27"

None None

time.tz Specifies a time in a subset of the ISO 8601 format with no date but optional time zone.

Example: "08:15:27-05:00"

None None

ui1 Specifies a 1-byte unsigned integer ranging from 0 to 255.

Examples: 1, 255

Integer unsignedByte

ui2 Specifies a 2-byte unsigned integer ranging from 0 to 65535.

Examples: 1, 255, 65535

Integer unsignedShort

ui4 Specifies a 4-byte unsigned integer ranging from 0 to 4294967296.

Examples: 1, 703, 3000000000

Character or Integer

unsignedInt

ui8 Specifies an 8-byte unsigned integer ranging from 0 to 18446744073709551615.

Example: 1483433434334

Character or Integer

unsignedLong

uri Identifies a Uniform Resource Identifier (URI).

Example: "urn:schemas-microsoft-com:Office9"

Memo anyURI

uuid Contains hexadecimal digits representing octets with optional embedded hyphens that are ignored.

Example: 333C7BC4-460F-11D0-BC04-0080C7055A83

Visual FoxPro Data and Field TypesVisual Studio 2005Other Versions

6 out of 7 rated this helpful Rate this topicAll data in Visual FoxPro have a particular data type, which defines values permitted for the data and the range and size of those values. After you identify and specify the data type you are using, Visual FoxPro can efficiently store and manipulate the data.

When you create a table, you can specify the type of data to store in each field of the table. You can specify more data types for fields in a table than for variables and arrays. Variables and arrays can store only a subset of the available Visual FoxPro data types; however. The value you store in a variable or array element determines the type of data in the variable or array element. For more information, see How to: Choose Data Types.

TipYou can use the TYPE(   )  function to determine the type of data stored in a variable, array element, or field.

Visual FoxPro Data Types

Data type

Description Size Range

Blob Binary data of indeterminate length.

Blob values are in a memo (.fpt) file.

No code page translation is performed onBlob data.

4 bytes in a table

Limited by available memory and/or 2GB file size limit.

Character Alphanumeric text

For example, a customer address

1 byte per character to 254

Any characters

Currency Monetary amounts

For example, the price of an item

8 bytes - $922337203685477.5807 to $922337203685477.5807

Date Chronological data consisting of month, day, and year

For example, an order date

8 bytes When using strict date formats, {^0001-01-01}, January 1st, 1 A.D to {^9999-12-31}, December 31st, 9999 A.D.

DateTime Chronological data consisting of month, day, year, hours, minutes, and seconds

For example, date and time of arrival

8 bytes When using strict date formats, {^0001-01-01}, January 1st, 1 A.D to {^9999-12-31}, December 31st, 9999 A.D., plus 00:00:00 a.m. to 11:59:59 p.m.

Logical Boolean value of True or False

For example, whether or not an order has been filled

1 byte True (.T.) or False (.F.)

Numeric Integers or decimal numbers

For example, the quantity of items ordered

8 bytes in memory; 1 to 20 bytes in table

- .9999999999E+19 to .9999999999E+20

Varbinary

Binary values.

Varbinary data is similar to Varchar data in that values do not include padding with zero (0) bytes. The length of the contained value is stored internally.

No code page translation is performed onVarbinary data.

1 byte per hexadecimal value up to 255 total bytes

Any hexadecimal value

Variant Variant data can be any of the Visual FoxPro data types and the null value.

Once a value is stored to a variant, the variant assumes the data type of

See other data types.

See other data types.

the data it contains.

Variants are designated with an e prefix in language syntax.

In addition, Visual FoxPro provides data types that apply only to fields in tables.

Visual FoxPro Field Types

Field type

Description Size Range

Character (Binary)

Any Character data that you do not want translated across code pages

For example, user passwords stored in a table and used in different countries or regions.

1 byte per character to 254

Any characters

Double A double-precision floating-point number

For example, scientific data requiring a high degree of precision.

8 bytes +/-4.94065645841247E-324 to +/-8.9884656743115E307

Float Same as Numeric 8 bytes in memory; 1 to 20 bytes in table

- .9999999999E+19 to .9999999999E+20

General Reference to an OLE object

For example, a Microsoft Excel worksheet.

4 bytes in table

Limited by available memory.

Integer Numeric value with no decimals

For example, a line number in an order.

4 bytes -2147483647 to 2147483647

Integer (Autoinc)

Same as Integer but also an automatically incrementing value. Read-only.

4 bytes Value controlled by autoincrement Next and Step values.

Memo Alphanumeric text of indeterminate length or reference to a block of data

For example, notes about a phone call in a phone log.

4 bytes in table

Limited by available memory.

Memo (Binary)

Same as Memo except that memo field data does not change across code pages

For example, a login script used in different countries or regions.

4 bytes in table

Limited by available memory.

Varchar Alphanumeric text.

Varchar is similar to Character except values in Varcharfields do not include padding with additional spaces. The length of the contained value is stored internally.

1 byte per character up to 254 total bytes

Any characters

Varchar (Binary)

Varchar type data that you do not want translated across code pages.

1 byte per character up to 254 total bytes

Any characters

Each data type has its own characteristics, including storage size:

Data Type Storage Differences

To see a list of the functions you can use with each data type, see Language Categories.