Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Processing an XML file to VFP cursors
Message
De
21/05/2004 03:52:09
 
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Divers
Thread ID:
00904549
Message ID:
00905916
Vues:
41
>Hi Aleskey,
>
>Thanks for your response.
>Going back to the original solution you gave me, I was hoping that I could use the ChildTable function as you suggest.
>When I try to use it I am getting a NULL value in the messagebox below.
>
>Am I using this incorrectly ?
>Unless there are related values in each table I cant see how this function will show me the foreign key.
>
>
>For Each oXT In oXA.Tables
>
> oXT.ToCursor(.T.)
> Select (oXT.Alias)
> BROWSE
>
> =MESSAGEBOX(oXT.ChildTable)
>
>Next
>
>
>-Carmel


Hi Carmel,

XMLAdapter doesn't set XMLTable.ChildTable property unless there is an XDR schema in the document. In this particular case, there is no XDR schema and it has to be set manually. Below is the code that uses ChildTable property to achieve the result similar to XPath scripting - pulling primary key (customer_number) from customer into foreign key field in sales and billing. However, I would recommend to use XPath scripting because it requires less coding, fairly straightforward and easier to understand.
CLOSE DATABASES all
CLEAR

CREATE CURSOR customer ;
(;
customer_number c(6),;
address_id I,;
name c(20);
)

CREATE CURSOR sales ;
(;
customer_number c(6) NULL,;
name c(20),;
email c(20),;
price_profile c(10),;
price_profile_email c(50);
)

CREATE CURSOR billing;
(;
customer_number c(6) NULL,;
address_id I,;
title c(20),;
firstname c(20),;
lastname c(20),;
company c(30);
)

LOCAL oXA as XMLAdapter, oXT as XMLTable

oXA=CREATEOBJECT("XMLAdapter")
oXA.LoadXML(GetXML())

oXT=oXA.AddTableSchema("customer")
	oXT.ToCursor(.T.)
	SELECT (oXT.Alias)
	?ALIAS()
	LIST
* remove all fields but customer_number 
DO WHILE oXT.Fields.Count>1
	oXT.Fields.Remove(2)
ENDDO 

JoinToCustomer(oXT,oXA.AddTableSchema("sales"))
	oXT.ToCursor(.T.)
	SELECT (oXT.Alias)
	?ALIAS()
	LIST

JoinToCustomer(oXT,oXA.AddTableSchema("billing"))
	oXT.ToCursor(.T.)
	SELECT (oXT.Alias)
	?ALIAS()
	LIST

FUNCTION JoinToCustomer(oXTCustomer as XMLTable, oXT as XMLTable)
* assume that customer_number is enough	to restore the relationship
LOCAL oXF as XMLField, oXA as XMLAdapter 

* redirect output to the proper cursor
oXTCustomer.Alias=oXT.Alias

oXA=oXTCustomer.XMLAdapter
nIndex=oXA.Tables.GetKey(oXT.XMLName)
oXA.Tables.Remove(oXT.XMLName)

oXTCustomer.ChildTable=oXT 

* remove customer_number from the ChildTable, it'll come from oXTCustomer
nIndex=oXT.Fields.GetKey(STRCONV("customer_number",5))
oXF=oXT.Fields(nIndex)
oXT.Fields.Remove(nIndex)

ENDFUNC 


FUNCTION GetXML()

TEXT TO cXML NOSHOW
<?xml version="1.0" encoding="UTF-8"?>
<export_customers_response>
  <authentication>
    <revision>2.0</revision>
    <reseller_shortcut>eric</reseller_shortcut>
    <user_email>test@test.com</user_email>
  </authentication>
  <customers>
    <customer>
      <customer_number>AC0127</customer_number>
      <address_id>626</address_id>
      <name>acme corp</name>
      <address1>1234 lane ave</address1>
      <address2 />
      <address_line1>1234 lane ave</address_line1>
      <address_line2 />
      <city>powell</city>
      <state>Ohio</state>
      <state_abbrv>OH</state_abbrv>
      <zip>43065</zip>
      <country>United States</country>
      <country_abbrv>USA</country_abbrv>
      <phone />
      <fax />
      <website />
      <lead_source />
      <tax_exempt />
      <tax_id />
      <comments />
      <terms>No Terms</terms>
      <credit_limit />
      <sales>
        <name>Lundin, Eric</name>
        <email>eric.lundin@cnet.com</email>
        <price_profile>22% Mark-Up</price_profile>
        <price_profile_email>channelsupport@cnet.com</price_profile_email>
      </sales>
      <billing>
        <address_id>627</address_id>
        <title />
        <firstname>pat</firstname>
        <lastname>leneghan</lastname>
        <company>acme corp</company>
        <address1>1234 lane ave</address1>
        <address2 />
        <city>powell</city>
        <state>Ohio</state>
        <state_abbrv>OH</state_abbrv>
        <zip>43065</zip>
        <country>United States</country>
        <phone />
        <extension />
      </billing>
      <shipping>
        <address_id>627</address_id>
        <title />
        <firstname>pat</firstname>
        <lastname>leneghan</lastname>
        <company>acme corp</company>
        <address1>1234 lane ave</address1>
        <address2 />
        <city>powell</city>
        <state>Ohio</state>
        <state_abbrv>OH</state_abbrv>
        <zip>43065</zip>
        <country>United States</country>
        <phone />
        <extension />
      </shipping>
      <contact>
        <address_id>166722</address_id>
        <title />
        <firstname>pat</firstname>
        <lastname>leneghan</lastname>
        <company>acme corp</company>
        <address1>1234 lane ave</address1>
        <address2 />
        <city>powell</city>
        <state>Ohio</state>
        <state_abbrv>OH</state_abbrv>
        <zip>43065</zip>
        <country>United States</country>
        <phone />
        <extension />
        <home_phone />
        <home_extension />
        <fax />
        <fax_extension />
        <email>pleneghan@aol.com</email>
        <mobile />
        <mobile_extension />
        <pager />
        <website />
        <other />
        <other_extension />
      </contact>
    </customer>
  </customers>
</export_customers_response>
ENDTEXT 

RETURN cXML
ENDFUNC
Thanks,
Aleksey.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform