Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create a cursor from an XML file
Message
From
02/01/2017 09:17:14
Thomas Ganss (Online)
Main Trend
Frankfurt, Germany
 
 
To
02/01/2017 07:19:06
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01646245
Message ID:
01646255
Views:
54
Well, structure is data as well - I'd probably view the XML as a type of protocol, but implement creating the payload via "structure extended" or afields().
Creating the the cursor client side would be reading in the field descriptors in a standardized table or array again and use vfp commands ;-)

That way server and vfp clients have the benefit of speed, brevity and clarity while still keeping the transmission protocol "internet typical&friendly"



>Well, I should have read your requirement a bit more carefully... It's not about data, it's about structure...
>
>The answer would be: "the XML would look like an XML Schema". Unfortunately, as far as I could understand, XMLTOCURSOR() interprets only the first element definition in a schema, so it seems that there is no way to hold different structure definitions inside a single schema that can be independently referenced.
>
>If you really prefer to have all definitions in a single file, as you stated (but Thomas presented a few arguments against it you should at least consider), an alternative approach would be to create the XML with an inline schema, and grab the definition from the overall schema pool.
>
>Something like this:
>a) start by create the cursors schema and store it in cursors.xsd
>b) the function CreateCursorFromXSD creates an XML string with an empty cursor top element, and an inline schema fetched from the cursors.xsd
>c) and then invokes XMLTOCURSOR() to create an empty cursor
>
>
>LOCAL CursorDefinitions AS String
>
>TEXT TO m.CursorDefinitions NOSHOW FLAGS 1
><?xml version="1.0" encoding="windows-1252"?>
><xsd:schema id="VFPSchema"
>  targetNamespace="http://microsoft.com"
>  xmlns="http://microsoft.com"
>  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>  xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified">
>  <xsd:element name="VFPData">
>    <xsd:complexType>
>      <xsd:choice maxOccurs="unbounded">
>		  <!-- the cursor definitions -->
>		  <!-- PERSONS -->
>		  <xsd:element name="person">
>			  <xsd:complexType>
>			    <xsd:sequence>
>			      <xsd:element name="name">
>			        <xsd:simpleType>
>			          <xsd:restriction base="xsd:string">
>			            <xsd:maxLength value="50"/>
>			          </xsd:restriction>
>			        </xsd:simpleType>
>			      </xsd:element>
>			      <xsd:element name="gender">
>			        <xsd:simpleType>
>			          <xsd:restriction base="xsd:string">
>			            <xsd:maxLength value="1"/>
>			          </xsd:restriction>
>			        </xsd:simpleType>
>			      </xsd:element>
>			      <xsd:element name="born" type="xsd:date"/>
>			    </xsd:sequence>
>			  </xsd:complexType>
>		  </xsd:element>
>		  <!-- CARS -->
>		  <xsd:element name="car">
>			  <xsd:complexType>
>			    <xsd:sequence>
>			      <xsd:element name="brand">
>			        <xsd:simpleType>
>			          <xsd:restriction base="xsd:string">
>			            <xsd:maxLength value="50"/>
>			          </xsd:restriction>
>			        </xsd:simpleType>
>			      </xsd:element>
>			      <xsd:element name="model">
>			        <xsd:simpleType>
>			          <xsd:restriction base="xsd:string">
>			            <xsd:maxLength value="50"/>
>			          </xsd:restriction>
>			        </xsd:simpleType>
>			      </xsd:element>
>			      <xsd:element name="year" type="xsd:int"/>
>			    </xsd:sequence>
>			  </xsd:complexType>
>		  </xsd:element>		  
>      </xsd:choice>
>    </xsd:complexType>
>  </xsd:element>
></xsd:schema>
>ENDTEXT
>
>STRTOFILE(m.CursorDefinitions, "cursors.xsd")
>
>CreateCursorFromXSD("persons", "person")
>CreateCursorFromXSD("cars", "car")
>
>SELECT Persons
>BROWSE NOWAIT
>
>SELECT Cars
>BROWSE NOWAIT
>MOVE WINDOW Cars BY 5, 10
>
>FUNCTION CreateCursorFromXSD (CursorName AS String, CursorType AS String) AS Boolean
>
>	LOCAL CursorCreator AS String
>	LOCAL XSD AS MSXML2.DOMDocument60
>	LOCAL CursorDefinition AS MSXML2.IXMLDOMNodeList
>
>	m.XSD = CREATEOBJECT("MSXML2.DOMDocument.6.0")
>	m.XSD.Async = .F.
>	m.XSD.Load("cursors.xsd")
>	m.XSD.Setproperty("SelectionNamespaces", "xmlns:xsd='http://www.w3.org/2001/XMLSchema'")
>	m.CursorDefinition = m.XSD.Selectnodes("//xsd:element[@name='" + m.CursorType + "']")
>	
>	SET TEXTMERGE DELIMITERS TO "««", "»»"
>	
>	USE IN SELECT(m.CursorName)
>
>	TEXT TO m.CursorCreator TEXTMERGE NOSHOW FLAGS 1 PRETEXT 3
>		<?xml version="1.0" encoding="windows-1252"?>
>		<VFPData xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
>			<xsd:schema id="VFPData">
>				<xsd:element name="VFPData" msdata:IsDataSet="true">
>					<xsd:complexType>
>						<xsd:choice maxOccurs="unbounded">
>							««m.CursorDefinition.item(0).xml»»
>						</xsd:choice>
>					</xsd:complexType>
>				</xsd:element>
>			</xsd:schema>
>			<««m.CursorType»» />
>		</VFPData>
>	ENDTEXT
>	
>	SET TEXTMERGE DELIMITERS
>
>	XMLTOCURSOR(m.CursorCreator, m.CursorName)
>
>ENDFUNC
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform