This method creates a DTD from the currently active Alias's data structure. The DTD generated is not complete in that it lacks the DocType and top level document root definition. This is so you can string together multiple cursors or objects in a single DTD.
The generated DTD elements look like this for a table:
<!ELEMENT wwbanners (row)*> <!ELEMENT row (bannerid,image,link,redirect,imgtags,order,type,hits,maxhits,clicks,test,test2)> <!ELEMENT bannerid (#PCDATA)> <!ATTLIST bannerid type CDATA #FIXED "string" size CDATA #FIXED "8" > ... more elements here <!ELEMENT image (#PCDATA)> <!ATTLIST image type CDATA #FIXED "string" size CDATA #FIXED "50" >
Note that the DocType DTD header and the docroot element are missing as well as the DTD closing tags:
<!DOCTYPE xdoc [ <!ELEMENT xdoc (wwbanners)> ... element code from above goes here ]>
Note that this setup allows for maximum configuration at the expense of some ease of use. However, it's fairly easy to create the DTD header and footer with a single line of code. The following is actually what CursorToXML does:
IF THIS.lCreateDataStructure lcOutput = lcOutput + ; "<!DOCTYPE " + THIS.cDocRootName + " [" + CR + ; "<!ELEMENT " + THIS.cDocRootName + " (" + lcName + ")>" + CR + ; THIS.CreateDataStructureDTD(lcName, lcRowName) + CR + ; "]>" + CR + CR ENDIF
If you were to add additional tables or objects you'd have to add them to the lcName code above.
o.CreateDataStructureXML(lcName, lcRowName, lnIndent, loRS)
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"
loRS
Optional - if passed the DTD is created from an ADO recordset rather than from a VFP cursor.
Remarks
Check cErrorMsg if the result is "" or an error occurs.
Example
*** Fox Usage #INCLUDE WCONNECT.H Use MyTestFile oXML = CREATE("wwXML") *** Indent at second level lcOutput = "<mytables>" + CR lcOutput = lcOutput + ; oXML.CreateDataStructureXML("MyTestFile",2) lcOutput = lcOutput + oXML.CreateCursorXML("MyTestFile",2) *** Additional files Use AnotherFile lcOutput = lcOutput + ; oXML.CreateDataStructureXML(Alias(),2) lcOutput = lcOutput + oXML.CreateCursorXML(Alias(),2) lcOutput = lcOutput + "</mytables>" + CR lcOutput = "<?xml version="1.0"?> + CR + lcOutput
<!-- Generated XML --> <?xml version="1.0"?> <cursors> <datastructure Name="Banners"> <field name="bannerid" type="string" size="8"/> <field name="image" type="string" size="50"/> <field name="link" type="string" size="128"/> <field name="redirect" type="string" size="128"/> <field name="imgtags" type="string" size="40"/> <field name="order" type="number" size="2"/> <field name="type" type="string" size="15"/> <field name="hits" type="i4" size="4"/> <field name="maxhits" type="i4" size="4"/> <field name="clicks" type="i4" size="4"/> <field name="test" type="bin.hex" size="4"/> </datastructure> <cursor Name="Banners"> <row> <bannerid>00000111</bannerid> <image>toolbar.gif</image> <link>http://www.west-wind.com/rick.htm</link> <redirect/> <imgtags>ALIGN=LEFT HSPACE=4</imgtags> <order>0</order> <type/> <hits>147</hits> <maxhits>90000</maxhits> <clicks>0</clicks> <test/> </row> <row> <bannerid>RL31B79O</bannerid> <image>wconnect.gif</image> <link>wc.dll?wwdemo~Banners~Click~RL31B79O</link> <redirect>http://www.west-wind.com/wwcgi.htm</redirect> <imgtags>ALIGN=LEFT HSPACE=6</imgtags> <order>0</order> <type/> <hits>47</hits> <maxhits>12312</maxhits> <clicks>2</clicks> </row> </cursor> <datastructure Name="REQUESTLOG"> <field name="time" type="datetime.iso8601" size="8"/> <field name="querystr" type="bin.hex" size="4"/> <field name="script" type="bin.hex" size="4"/> <field name="remoteaddr" type="bin.hex" size="4"/> <field name="duration" type="number" size="5" precision="2"/> <field name="error" type="boolean" size="1"/> </datastructure> <cursor Name="REQUESTLOG"> <row> <time></time> <querystr/> <script/> <remoteaddr/> <duration>0</duration> <error>.F.</error> </row> <row> <time>19990203T11:26:32 AM</time> <querystr>wwmaint~showlog</querystr> <script>wc.acx</script> <remoteaddr>751060 - 127.0.0.1</remoteaddr> <duration>0.13</duration> <error>.F.</error> </row> </cursor> </cursors>
See also:
Class wwXML (High Level Methods) | wwXML::CreateDataStructureSchema | wwxml::nCreateDataStructure© West Wind Technologies, 1996-2024 • Updated: 07/28/00
Comment or report problem with topic