CURSORTOXML( ) Function
Visual FoxPro 9.0 SP2 |
CURSORTOXML( ) Function |
See Also |
![]() |
Converts a Visual FoxPro cursor to XML.
CURSORTOXML(nWorkArea | cTableAlias, cOutput [, nOutputFormat [, nFlags [, nRecords [, cSchemaName [, cSchemaLocation [, cNameSpace ]]]]]]) |
Parameters
- nWorkArea
-
Specifies the work area of the table from which to create the XML string.
If you specify 0 or no value, Visual FoxPro uses the current work area.
- cTableAlias
-
Specifies the alias of the table from which to create the XML string.
- cOutput
-
Specifies the path and file name or memory variable name to which results are sent.
If nFlags is set to 0 (default) for memory variable output, XML is returned to the memory variable. If the memory variable does not exist, it is created.
If nFlags is set to 512 for file output, and the file does not exist, it is created. If the file already exists, it is overwritten. The setting for SET SAFETY is observed.
- nOutputFormat
-
Specifies the output format of the XML string. The following table lists the values for nOutputFormat.
nOuputFormat Description 1 – ELEMENTS
(Default) Element-centric XML
2 – ATTRIBUTES
Attribute-centric XML
3 – RAW
Generic, attribute-centric XML
- nFlags
-
Specifies the formatting of the XML that is produced and its destination. The following table lists the values for nFlags.
nFlags Bit Output description 0
0000
(Default) Produce XML in UTF-8 format.
This setting creates a memory variable if one does not exist when specified by cOutput and returns XML to the memory variable.
The XML declaration does not contain an Encoding= attribute; that is, no encoding attribute is set to UTF-8.
1
0001
Produce unformatted XML as a continuous string.
2
0010
Enclose empty elements with 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. Output is set to the cursor code page.
To ensure accurate character translation, the Visual FoxPro default code page must match the code page of the cursor. You can accomplish this by setting character and memo fields in the cursor to NOCPTRAN (character binary/memo binary).
When setting this value with tables using any of the code pages, the encoding attribute in the XML is set to an empty string (""). To change to the correct encoding attribute, use the STRTRAN( ) function.
For example, for code page 936, provide the following to the resulting XML string:
Copy Code
strxml=STRTRAN(strxml, 'encoding=""', 'encoding="gb2312"'
32
100000
Output encoding.
512
1000000000
Output to the file specified by cOutput.
If a file does not exist, it is created. If the file already exists, it is overwritten. The setting for SET SAFETY is observed.
4096
1000000000000
Disables base64 encoding.
CURSORTOXML( ) exports Memo (Binary) fields as xsd:base64binary unless you use nFlags set to 4096. In Visual FoxPro, base64 encoding is meant for encoding only binary data.
32768
none
Indicates that a code page should be used.
The following table describes how the encoding attribute is written when output encoding defaults to the cursor or table code page.
Note
Encoding 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 cursor code page.
+32
10
Set output encoding attribute to UTF-8 with no character translation.
+48
11
Set output encoding attribute to UTF-8 and translate character data to UTF-8.
The following table lists common Windows-compatible code pages.
Code page Platform Encoding attribute in XML Declaration Comments 437
MS-DOS, US
ibm437
850
MS-DOS, International
ibm850
865
MS-DOS, Nordic
Empty string ("")
866
MS-DOS, Russian
cp866
932
Windows, Japanese
shift-jis
936
Simplified Chinese
gb2312
949
Windows, Korean
iso-2022-kr
or:
ks_c_5601-1987
950
Windows, Traditional Chinese (Taiwan)
big5
1250
Windows, East European
Windows-1250
Note case.
1251
Windows, Russian
Windows-1251
1252
Windows, U.S., West European
Windows-1252
1253
Windows, Greek
Windows-1253
1254
Windows, Turkish
Windows-1254
1255
Windows, Hebrew
Windows-1255
1256
Windows, Arabic
Windows-1256
Note
Visual FoxPro uses Windows-1252 as the default encoding. You can specify that the encoding attribute be set to match the code page, such as Big5 (code page 950), when using double-byte character sets (DBCS) for DBCS languages for which Visual FoxPro supports code pages.
When using Windows-1252 and DBCS, no additional character translation is required to display correctly in Internet Explorer.
However, to make XML more compliant for Web browsers that can interpret UTF-8, you can optionally set the encoding attribute to UTF-8 instead of Windows-1252. The result set undergoes translation to UTF-8 characters only when you set nFlags to 48 (specify the encoding attribute as UTF-8 and translate character data to UTF-8 format). This is required only when the data actually contains double-byte characters. You do not have to use character translation, STRCONV ( ), for example, if you are outputting only Latin (single byte) characters.
- nRecords
-
Specifies the number of records to output to XML and has a default value is 0.
If nRecords is 0, all records are output. If nRecords is greater than the number of records remaining in the table, all remaining records are output.
- cSchemaName
-
Specifies the name and location to contain schema information for the data in cOutput, for example "MySchema.xsd". If no extension is provided, the schema file is created with an .xsd extension.
The following table lists the values for cSchemaName.
cSchemaName Description cSchemaName
Specifies the name and path of the external file for the schema (scoped to the root element of the XML).
Note
If cSchemaName contains a file name and cSchemaLocation is not provided or is blank, the contents of cSchemaName are written to the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute in the XML.
In the following example, Visual FoxPro generates a generic XML file named MyXMLFile.xml from the Labels.dbf file in the "Labels" alias and the schema file named MySchema in the same folder.
Copy Code
CURSORTOXML("LABELS", "myXMLFile.xml", 1, 512, 0, "mySchema.xsd")
If cSchemaName includes a URI, the schema is written to the current directory and must be uploaded to the server to be accessed by the browser or parser. External schemas always are written to the same location as the XML file.
"1"
Specifies an inline schema is produced. For example, the following code produces an inline schema:
Copy Code
CURSORTOXML("LABELS", "myXMLFile.xml", 1, 512, 0, "1")
""
Specifies that no schema is produced.
- cSchemaLocation
-
Specifies an optional location where the application reading the XML data should look for the schema file.
Note
Use this parameter only when you are deploying your schema to a location other than the location of the XML data.
The contents of cSchemaLocation are written to the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute of the XML data produced. The cschemaLocation parameter can be an HTTP address or other URI. You need to copy the schema file to the location you have specified in cSchemaLocation.
The following example produces XML data:
Copy Code
CURSORTOXML("LABELS", "myXMLFile.xml", 1, 512, 0, ; "mySchema.xsd", "http://www.microsoft.com/mySchema.xsd")
containing the following attribute:
Copy Code
xsi:noNamespaceSchemaLocation=" http://www.microsoft.com/mySchema.xsd"
Specifying cSchemaLocation when cSchemaName is blank causes the same attributes to be written to the XML data. This makes it possible for you to point to an existing schema without recreating the schema each time CURSORTOXML( ) is called.
- cNamespace
-
Specifies the namespace of the XML or schema to be produced and has an empty string ("") as the default value.
Specifying a value for cNameSpace sets the targetNamespace attribute to the same value and adds the elementFormDefault="qualified" attribute to the schema.
If you do not specify a cNamespace value, and the schema is external, no namespace declaration is written to the schema. If you do not specify a cNamespace value and the schema is inline, the targetNamespace in the schema is set to an empty string ("").
Return Value
Remarks
See Also
© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic