Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XMLAdapter maps Integer to C(254)
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01091350
Message ID:
01091626
Vues:
21
This message has been marked as the solution to the initial question of the thread.
>XMLAdapter seems to map XML Integer attributes to Character (254) as opposed to VFP Integers as one would expect.
>


Hi Nick,

When XMLAdapter maps XML data type to VFP data type, it uses xsd:totalDigits facet to determine if data can be stored in integer field. You can adjust the schema to include this facet or simply adjust DataType property for XMLField object, see example below. If you can't modify the schema and there are many fields like that and all of them fit into VFP Integer field, you can loop through all XMLField objects and adjust DataType for fields with XSDType="integer". If there are some xsd:integer fields that don't fit, you can skip them by analyzing ISchemaType object stored in XMLType property.
CLEAR
CLOSE DATABASES ALL

TEXT TO cXML1 NOSHOW
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
<VFPDataSet>
	<xsd:schema id="VFPDataSet" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
		<xsd:element name="VFPDataSet" msdata:IsDataSet="true">
			<xsd:complexType>
				<xsd:choice maxOccurs="unbounded">
					<xsd:element name="foo" minOccurs="0" maxOccurs="unbounded">
						<xsd:complexType>
							<xsd:sequence>
								<xsd:element name="f1">
									<xsd:simpleType>
										<xsd:restriction base="xsd:integer">
											<xsd:minInclusive value="1"/>
											<xsd:maxInclusive value="999999"/>
										</xsd:restriction>
									</xsd:simpleType>
								</xsd:element>
							</xsd:sequence>
						</xsd:complexType>
					</xsd:element>
				</xsd:choice>
				<xsd:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" 
					processContents="lax"/>
			</xsd:complexType>
		</xsd:element>
	</xsd:schema>
</VFPDataSet>
ENDTEXT

TEXT TO cXML2 NOSHOW
<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
<VFPDataSet>
	<xsd:schema id="VFPDataSet" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
		<xsd:element name="VFPDataSet" msdata:IsDataSet="true">
			<xsd:complexType>
				<xsd:choice maxOccurs="unbounded">
					<xsd:element name="foo" minOccurs="0" maxOccurs="unbounded">
						<xsd:complexType>
							<xsd:sequence>
								<xsd:element name="f1">
									<xsd:simpleType>
										<xsd:restriction base="xsd:integer">
											<xsd:totalDigits value="6"/>
											<xsd:minInclusive value="1"/>
											<xsd:maxInclusive value="999999"/>
										</xsd:restriction>
									</xsd:simpleType>
								</xsd:element>
							</xsd:sequence>
						</xsd:complexType>
					</xsd:element>
				</xsd:choice>
				<xsd:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" 
					processContents="lax"/>
			</xsd:complexType>
		</xsd:element>
	</xsd:schema>
</VFPDataSet>
ENDTEXT

LOCAL oXA as XMLAdapter

oXA = createobject( "XMLAdapter")
oXA.LoadXML(cXML1,.F.)
oXA.Tables(1).ToCursor()
SELECT foo
DISPLAY STRUCTURE 
USE

?oXA.Tables(1).Fields(1).XSDType = "integer"
oXA.Tables(1).Fields(1).DataType = "I"
oXA.Tables(1).ToCursor()
SELECT foo
DISPLAY STRUCTURE 
USE

oXA.LoadXML(cXML2,.F.)
oXA.Tables(1).ToCursor()
SELECT foo
DISPLAY STRUCTURE 
USE
Thanks,
Aleksey.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform