Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any one ever use the XMLTable or XMLField class?
Message
From
20/01/2005 20:42:13
 
 
To
20/01/2005 19:49:55
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
00979031
Message ID:
00979154
Views:
14
Thanks David. And, yes, my imagination is triggered - funny how a simple example (like the one you just showed) can do just that.

>Jeff,
>
>>Has anyone ever used the XMLTable or XMLField classes seperately?
>>I'm not taliking about the XMLAdapter class which utilizes it's members.
>>How can these classes be used? Am I missing something?
>
>XMLTable and XMLField classes are intended to be used with the XMLAdapter. When you load in XML (using LoadXML method) or add a table reference (via AddTableSchema), the XMLAdapter Tables collection is created and populated and each table in the collection has its Fields collection created and populated.
>
>You can, however, play with them a bit and change things around, and this capability works nicely with the new XPath features of VFP9 XMLAdapter. That is a complex subject to get into (and I'm hoping we'll have a good article on it soon in FoxTalk), but just for fun, consider this.
>
>This piece of code is from a sample David Anderson allowed me to use during my XMLAdapter presentation at OzFox. Assume you have Table1 in the XML, and nested inside it is Table2. The following code instantiates an XMLField object, configures it as a foreign key to point to the key value of the Table1 record it is nested inside. Then, the XMLField object is added to the XMLTable object that defines Table2. (Note the new VFP9 property on the XMLField object, XMLNameIsXPath, and note that the XMLName property must be a Unicode string, which requires use of STRCONV.)
>
>Also note in the filtering example near the bottom that if you change an existing XMLTable or XMLField object already in the XMLAdapter to set it up for an XPath expression, you need to get a reference to the object first, then remove it from its parent, make the changes to set up XPath, then add it back to its former parent.
>
>This is just one possible use for separate XMLTable and XMLField classes and may trigger your imagination a bit.
CLOSE DATABASES all
>CLEAR
>
>LOCAL oXA as XMLAdapter, oXT as XMLTable, oXF as XMLField
>
>oXA=CREATEOBJECT("XMLAdapter")   && instantiate XML Adapter
>oXA.LoadXML("nested.XML",.T.)    && load the XML file
>
>FOR EACH oXT IN oXA.Tables       && Display # of tables in XML file
> oXT.ToCursor()
> SELECT (oXT.Alias)
> ?[ALIAS()],ALIAS()
> LIST
>NEXT
>
>WAIT window
>
>TEXT
>Note, there is no way to determine relationship
>between records in Table2 and Table1. In the XML
>document the relationship was represented through
>nesting. We can use XPath expression to get
>Tab1ID from the parent for each record in Table2.
>ENDTEXT
>WAIT window
>
>oXF=CREATEOBJECT("XMLField")                &&
>oXF.XMLNameIsXPath= .T.
>oXF.XMLName=STRCONV("parent::Table1/tab1id",5)
>oXF.Alias="tab1id"
>oXF.DataType="Int"
>oXT=oXA.Tables(STRCONV("Table2",5))
>oXT.Fields.Add(oXF,oXF.XMLName)
>
>CLOSE TABLES ALL
>
>FOR EACH oXT IN oXA.Tables
> oXT.ToCursor()
> SELECT (oXT.Alias)
> ?[ALIAS()],ALIAS()
> LIST
>NEXT
>
>WAIT window
>
>?"Let's filter out Table1 records that don't have any children."
>WAIT window
>
>oXT=oXA.Tables(STRCONV("Table1",5))
>oXA.Tables.Remove(STRCONV("Table1",5))
>oXT.XMLName=STRCONV("Table1[Table2]",5)
>oXA.Tables.Add(oXT,oXT.XMLName)
>
>CLOSE TABLES ALL
>
>FOR EACH oXT IN oXA.Tables
> oXT.ToCursor()
> SELECT (oXT.Alias)
> ?[ALIAS()],ALIAS()
> LIST
>NEXT
- Jeff
Previous
Reply
Map
View

Click here to load this message in the networking platform