wwxml::CursorToXML

This high level method creates a full XML document that exports a VFP cursor to an XML document. If you export the file with the nCreateDataStructure flag set to 1 the file will contain a Schema or 2 to contain a DTD that describes the data structure of the table.

XML created with this method can be converted back into a cursor by running XMLToCursor().

Note that the structure of the document is:

<docroot>
    <schema>  (optional)
 	</schema>
	<table>
		<row>
			<field></field>
		</row>
		<row>	
			<field></field>
		</row>	
 	</table>
</docroot>

You can create an embedded schema by setting the nCreateDataStructure property to 1. To create a DTD use a value of 2. Schemas are embedded and may not work in all but the latest XML parsers that support them. You can reference an external schema using the cSchemaUrl property. The schema should follow the rules of CreateDataStructureSchema.

o.cursortoxml(lcName, lcRowName, lnIndent, llNoHeader)

Return Value

XML String

Parameters

lcName
Optional - element name used at the table level. Note this tag sits underneath the document root. (wwBanners in the example).

  • Default value:* The name of the current Alias().

lcRowName
Optional - The element name used for each row of the cursor.

  • Default value:* "row"

lnIndent
Optional - Indentation level to start with.

llNoHeader
Optional - Leave out the XML Header

Remarks

  • The document format hierarchy must be . Naming is not required as long as hierarchy is intact

  • All tags are created as lower case tags from fieldanames. Any tags you assign (docroot and row level) maintain their case.

  • The nCreateDataStructure flag determines whether a schema or DTD is created. The DTD or Schema contain the data structure for the cursor. Use this if you need to reassemble the table back into a cursor on the other end of a dynamic XML connection or Web request.

  • The data format may change in the future to conform to an XML data standard. The current implementation is built for maximum flexibility and performance and is mainly intended to allow reassembling of data on both ends of the connection. The structure is also built for extensibilty to allow combination of multiple cursors/object/XML fragments into a single document.

Example

use wwBanners

*** DTD example - (Schema version below)
oXML = CREATE("wwXML")
oXML.nCreateDataStructure = 2  && DTD
ShowText( oXML.CursorToXML() )
<<hr>>
<!--- DTD version ---->
<?xml version="1.0"?>
<!DOCTYPE tt_cust [
<!ELEMENT tt_cust (customers)>
<!ELEMENT customers (customer)*>
<!ELEMENT customer (custno,company,careof,address,shipaddr,email,phone,billrate,btype,pk)>
<!ELEMENT custno (#PCDATA)>
<!ATTLIST custno
          type CDATA #FIXED "string"
          size CDATA #FIXED "8"
>
<!ELEMENT company (#PCDATA)>
<!ATTLIST company
          type CDATA #FIXED "string"
          size CDATA #FIXED "30"
>
<!ELEMENT careof (#PCDATA)>
<!ATTLIST careof
          type CDATA #FIXED "string"
          size CDATA #FIXED "30"
>
<!ELEMENT address (#PCDATA)>
<!ATTLIST address
          type CDATA #FIXED "string"
          size CDATA #FIXED "2147483647"
>
<!ELEMENT shipaddr (#PCDATA)>
<!ATTLIST shipaddr
          type CDATA #FIXED "string"
          size CDATA #FIXED "2147483647"
>
<!ELEMENT email (#PCDATA)>
<!ATTLIST email
          type CDATA #FIXED "string"
          size CDATA #FIXED "2147483647"
>
<!ELEMENT phone (#PCDATA)>
<!ATTLIST phone
          type CDATA #FIXED "string"
          size CDATA #FIXED "2147483647"
>
<!ELEMENT billrate (#PCDATA)>
<!ATTLIST billrate
          type CDATA #FIXED "float"
          size CDATA #FIXED "7"
          precision CDATA #FIXED "2"
>
<!ELEMENT btype (#PCDATA)>
<!ATTLIST btype
          type CDATA #FIXED "string"
          size CDATA #FIXED "15"
>
<!ELEMENT pk (#PCDATA)>
<!ATTLIST pk
          type CDATA #FIXED "i4"
          size CDATA #FIXED "4"
>

]>

<tt_cust>
<customers>
	<customer>
		<custno>       2</custno>
		<company>BGP Productions</company>
		<careof>James Nolan</careof>
		<address><![CDATA[34 Eastland Road
Suite C104
Diversion, MA  01111]]></address>
		<shipaddr/>
		<email/>
		<phone><![CDATA[Voice:  312-233-3333
Fax:    312-232-3322
Data:   312-232-0001]]></phone>
		<billrate>45</billrate>
		<btype>Labor_PRG</btype>
		<pk>2</pk>
	</customer>
	<customer>
		<custno>       4</custno>
		<company>Golf Reproductions</company>
		<pk>42</pk>
		...
	</customer>
</customers>

</tt_cust>

<<hr>>
*** Schema Version
oXML = CREATE("wwXML")
oXML.lCreateDataStructure = 1  && Schema
ShowText( oXML.CursorToXML() )
<<hr>>
<?xml version="1.0"?>
<tt_cust>
<Schema name="Schema" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
   <ElementType name="customers" content="eltOnly" model="closed" order="many">
		<element type="customer" />
	</ElementType>
	<ElementType name="customer" content="eltOnly" model="closed" order="many">
		<element type="custno"/>
		<element type="company"/>
		<element type="careof"/>
		<element type="address"/>
		<element type="shipaddr"/>
		<element type="email"/>
		<element type="phone"/>
		<element type="billrate"/>
		<element type="btype"/>
		<element type="pk"/>
	</ElementType>
	<ElementType name="custno" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="8"/>
	</ElementType>
	<ElementType name="company" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="30"/>
	</ElementType>
	<ElementType name="careof" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="30"/>
	</ElementType>
	<ElementType name="address" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="2147483647"/>
	</ElementType>
	<ElementType name="shipaddr" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="2147483647"/>
	</ElementType>
	<ElementType name="email" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="2147483647"/>
	</ElementType>
	<ElementType name="phone" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="2147483647"/>
	</ElementType>
	<ElementType name="billrate" content="textOnly" model="closed" dt:type="float">
		<AttributeType name="type"/>
		<attribute type="type" default="float"/>
		<AttributeType name="size"/>
		<attribute type="size" default="7"/>
		<AttributeType name="precision"/>
		<attribute type="precision" default="2"/>
	</ElementType>
	<ElementType name="btype" content="textOnly" model="closed" dt:type="string">
		<AttributeType name="type"/>
		<attribute type="type" default="string"/>
		<AttributeType name="size"/>
		<attribute type="size" default="15"/>
	</ElementType>
	<ElementType name="pk" content="textOnly" model="closed" dt:type="i4">
		<AttributeType name="type"/>
		<attribute type="type" default="i4"/>
		<AttributeType name="size"/>
		<attribute type="size" default="4"/>
	</ElementType>
</Schema>
<customers xmlns="x-schema:#Schema">
	<customer>
		<custno>       2</custno>
		<company>BGP Productions</company>
		<careof>James Nolan</careof>
		<address><![CDATA[34 Eastland Road
Suite C104
Diversion, MA  01111]]></address>
		<shipaddr/>
		<email/>
		<phone><![CDATA[Voice:  312-233-3333
Fax:    312-232-3322
Data:   312-232-0001]]></phone>
		<billrate>45</billrate>
		<btype>Labor_PRG</btype>
		<pk>2</pk>
	</customer>
	<customer>
		<custno>       4</custno>
		<company>Golf Reproductions</company>
 		...
	</customer>
</customers>
</tt_cust>

See also:

Class wwXML (High Level Methods) | wwXML::CreateCursorXML | wwxml::CreateDataStructureDTD | wwxml::CreateDataStructureSchema

© West Wind Technologies, 2023 • Updated: 12/09/18
Comment or report problem with topic