Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to VFP Fields rendering NULL values

Status
Not open for further replies.

VFPIt

IS-IT--Management
Jul 8, 2002
8
US
I am using XMLAdapter() using LoadXML() to load an XML file. One of the tables in the group gives me NULL values. If I hand type those values in the XML file, I can get the values reflected in the table.

What can be the problem ?
 
Can't tell you without seeing the XML. What could be a reason, is that there are no structural informations within the XML about the data, that is no embedded schema.

Predefining cursor(s) for LoadXML can solve that problem. I assume that is what you do when you say you're "hand typing those values".

Bye, Olaf.
 
first of all Thank You for your reply.

I am sending the program, XSD file and XML file with this post.

Please help me. :)

==== Program
CLEAR all
CLOSE all
RELEASE all
CLEAR

TEXT TO cxml noshow
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs=" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="PromoAvails" />
</xs:choice>
</xs:complexType>
</xs:element>

ENDTEXT

pcFile = GETFILE('XML', 'Select XML to open')
lcSchemaFile = GETFILE('XSD', 'Select XSD to open')
pcXSDFileName= lcSchemaFile
pcCallSign = 'ABCD'

cxsd=FILETOSTR(lcSchemaFile)
cxsd=SUBSTR(cxsd,AT("<",cxsd,3)) &&should start with <xs:element name

cxmlfile=FILETOSTR(pcFile)
cxmlfile=SUBSTR(cxmlfile,AT("<",cxmlfile,2))
cxmlfile=[<PromoAvails xmlns:xsi=" xsi:noNamespaceSchemaLocation="] + pcXSDFileName + [" logDate="2009-08-10" callSign="ABCD">]+ cxmlfile

finalcxml=cxml+cxsd+cxmlfile+"</NewDataSet>"
=STRTOFILE(finalcxml,'PromoAvails.xml')
LOCAL loMyXMLAD AS xmladapter
lcMyXMLFile = [PromoAvails.xml]
loMyXMLAD = NEWOBJECT([XMLADAPTER])
loMyXMLAD.LoadXML(finalcxml,.f., .f.)

FOR EACH oTable IN loMyXMLAD.TABLES
FOR EACH ofield IN otable.fields
IF ofield.datatype="M" THEN
ofield.datatype="C"
ofield.maxlength=50
ENDIF

IF oField.MaxLength > 230 THEN
oField.maxLength = 200
ENDIF
ENDFOR
oTable.TOCURSOR()
ENDFOR
SET STEP ON
SELECT('Inventory')
BROWSE

SET STEP ON



======= XSD FILE
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=" elementFormDefault="qualified">
<xs:element name="PromoAvails">
<xs:complexType>
<xs:sequence>
<xs:element name="Program" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Episode" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Break" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Inventory" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ScheduledPromo" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="promoId" type="xs:int" use="required"/>
<xs:attribute name="startTime" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="length" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="capacity" type="xs:string" use="required"/>
<xs:attribute name="capacityUsed" type="xs:string" use="required"/>
<xs:attribute name="startTime" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="logBreakId" type="xs:string" use="optional"/>
<xs:attribute name="housenumber" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="offsetLength" type="xs:string" use="optional"/>
<xs:attribute name="offsetframe" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="offsetdirection" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="number" type="xs:string" use="optional"/>
<xs:attribute name="name" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="startTime" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="length" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="referenceNumber" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="name" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="75"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="id" type="xs:string" use="optional"/>
<xs:attribute name="length" type="xs:string" use="optional"/>
<xs:attribute name="startTime" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="startTime" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="length" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="logDate" type="xs:date" use="required"/>
<xs:attribute name="callSign" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="6"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>



======== XML File
<PromoAvails logDate="2009-08-10" callSign="ABCD">
<Program startTime="06:30:00" id="PROGRAM ID" name="Craft Lab Mo 630A" length="00:30:00">
<Episode referenceNumber="DCLB-101" name="ABCDES" id="ABZCD-010" length="00:20:00" startTime="06:30:00">
<Break number="S1" name="S1" startTime="06:30:00" length="00:07:07">
<Inventory name="CC1" capacity="00:00:02" capacityUsed="00:00:00" startTime="06:30:00" logBreakId="5" houseNumber="" offsetLength="00:00:02" offsetFrame="00" offsetDirection="Forward" />
<Inventory name="CC2" capacity="00:00:02" capacityUsed="00:00:00" startTime="06:30:00" logBreakId="6" houseNumber="" offsetLength="00:00:30" offsetFrame="00" offsetDirection="Forward" />
<Inventory name="CC3" capacity="00:00:02" capacityUsed="00:00:00" startTime="06:30:00" logBreakId="7" houseNumber="" offsetLength="00:00:30" offsetFrame="00" offsetDirection="Backward" />
</Break>
</Episode>
</Program>
</PromoAvails>
 
I don't have the time. One thing catching my eye: The XML Encoding is "UTF-8", with all your fumbling with FILETOSTR() and STRTOFILE() you're changing this encoding to ANSI and XMLAdapter perhaps fails because of that.

There is no reason to change the XML to point to the file location o the XSD file, you can set the XSD schema via the XMLSchemalocation property of the XMLAdapter. This overrides what location is encoded in the XML. Only if you set XMLSchemalocation to "1" an inline schema or a schema reference in the XML will be searched.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top