Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XMLAdaptor LoadXML Multiple Tables
Message
From
31/10/2005 21:00:56
 
 
To
31/10/2005 19:38:13
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
01063866
Message ID:
01063879
Views:
20
Sarosh,

XMLAdapter requires some internal metadata based on a schema in order to do anything with XML that you load into it. If you don't have a schema, you can load your own internal metadata instead.

If you put the XML into a file called wadia.xml and put the following code into a PRG and run it, you will get two cursors. You will have to add more field definitions to the first table to get all the fields (look up properties of XMLField class in VFP Help), but this will get you started.
* wadia.prg -- read in wadia.xml and
* output 2 cursors via XMLAdapter
LOCAL oxa AS xmladapter
oxa=CREATEOBJECT("xmladapter")

* tell XMLAdapter we don't have a schema so it will
* go ahead and load the XML anyway
oxa.XMLSchemaLocation=""

* load the XML
oxa.LoadXML("wadia.xml",.T.)

* now set up your own internal schema to tell
* XMLAdapter where to find the tables and fields
*
* NOTE: You will have to add more XMLField
* objects in the code to get all the fields
* This code is just to show you how.
*
* NOTE: Tag names are case-sensitive
*
* NOTE: All XPath statements are relative to the
*   next-higher hierarchical level. The starting 
*   point is the "root" tag, which in this case
*   is <TestCard>

* CardMeta table
oTable = CREATEOBJECT("XMLTable")
* all XMLName properties must be Unicode
oTable.XMLName = STRCONV("CardMeta",5)
oTable.XMLNameIsXpath = .T.
* the cursor's alias
oTable.Alias = "cardmeta"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("DocId",5)
oField.XMLNameIsXpath = .T.
* field.alias means the field name you want
* in your cursor
oField.Alias = "docid"
oField.DataType = "C"
oField.MaxLength = 40
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("xeProjectNumber",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "xeprojectnumber"
oField.DataType = "C"
oField.MaxLength = 4
oTable.Fields.Add(oField, oField.XMLName)

*** You add more fields here for this table

* add the first table to the tables collection
oxa.Tables.Add(oTable, oTable.XMLName)

* ABCFile table
oTable = CREATEOBJECT("XMLTable")
oTable.XMLName = STRCONV("ABCFiles/ABCFile",5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = "abcfile"

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("ApplicationClass",5)
oField.XMLNameIsXpath = .T.
* NOTE: Field names can be different from the
* XML Tags
oField.Alias = "appclass"
oField.DataType = "C"
oField.MaxLength = 3
oTable.Fields.Add(oField, oField.XMLName)

oField = CREATEOBJECT("XMLField")
oField.XMLName = STRCONV("FileName",5)
oField.XMLNameIsXpath = .T.
oField.Alias = "filename"
* change data types if you like -- in this case,
* why not Varchar(100)?
oField.DataType = "V"
oField.MaxLength = 100
oTable.Fields.Add(oField, oField.XMLName)

oxa.Tables.Add(oTable, oTable.XMLName)

* now output and browse the 2 cursors
oxa.tables(1).toCursor()
BROWSE
oxa.tables(2).toCursor()
BROWSE
>Hi!
>
>We need to open an XML File which contains multiple tables and a nested table.
>
>There is no Schema (XSD) file along with it. I can open this XML file in Visual Studio 2005 no problem but the XMLAdapter for some reason cannot open it.
>
>
>Here is the sample XMl file.
>
>
><?xml version="1.0" encoding="UTF-8" ?>
><TestCard>
><CardMeta>
><DocId>FEAE7D6117849755C1257066004D9E4C</DocId>
><xeProjectNumber>9876</xeProjectNumber>
><xeSubProjectNumber></xeSubProjectNumber>
><xeSubProjectDescription></xeSubProjectDescription>
><xeProjectName>Project test</xeProjectName>
><xeTitle1>testing</xeTitle1>
><xeTitle2></xeTitle2>
><xeTitle3></xeTitle3>
><xeTitle4></xeTitle4>
><xeTitle5></xeTitle5>
><xeSOPId>48-9876/A.01A/001/1A</xeSOPId>
><xeIndex>001</xeIndex>
><xeDisciplineCode>A</xeDisciplineCode>
><TestDescription>Art</TestDescription>
><xeTypeCode>01A</xeTypeCode>
><TypeDescription>testdetail</TypeDescription>
><ModifiedBy>usera</ModifiedBy>
><wfRevisionCode>1A</wfRevisionCode>
><wfRevisionSubject>ISSUED FOR test</wfRevisionSubject>
><StatusTitle>Approved by test</StatusTitle>
><Site>48</Site>
><SiteDescription></SiteDescription>
><xeClientNumber></xeClientNumber>
><ClientName>My Self</ClientName>
><Media>ELECTRONIC</Media>
></CardMeta>
><ABCFiles>
><ABCFile>
><ApplicationClass>Pdf</ApplicationClass>
><FileName>test1.pdf</FileName>
></ABCFile>
><ABCFile>
><ApplicationClass>Pdf</ApplicationClass>
><FileName>test2.pdf</FileName>
></ABCFile>
><ABCFile>
><ApplicationClass>Pdf</ApplicationClass>
><FileName>test3.pdf</FileName>
></ABCFile>
></ABCFiles>
></TestCard>
>
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform