Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Paul Gibson
  Where is Paul Gibson?
 Glasgow
 United Kingdom
 Paul Gibson
 Tags
Subject: RE: Efficient XML Parsing
Thread ID: 372993 Message ID: 373279 # Views: 98 # Ratings: 6
Version: Visual FoxPro 9 SP2 Category: XML
Date: Wednesday, March 20, 2013 6:57:31 PM         
   


Paul,
I hope this helps (saved the XML as PaulGibson_data.xml):

dcSchemaPath =   Sys(2023) + "\PaulGibson_schema.xsd"
dcXMLPath    =  Sys(2023) + "\PaulGibson_data.xml"

Close Databases All
Local loAdapter As Xmladapter, ;
  loHelper, ;
  t1 As Xmltable, t2 As Xmltable, t3 As Xmltable, t4 As Xmltable, t5 As Xmltable, t6 As Xmltable
loHelper = Createobject('XMLAdapterUtils')

loAdapter = Createobject('XMLAdapter')
*loAdapter.XMLSchemaLocation = m.dcSchemaPath && I think there is something wrong with the schema
loAdapter.LoadXML( m.dcXMLPath, .T. )

t1 = loHelper.MakeTable("parent")
t2 = loHelper.MakeTable("source")
t3 = loHelper.MakeTable("destination")
t4 = loHelper.MakeTable("action")
t5 = loHelper.MakeTable("children")
t6 = loHelper.MakeTable("child")

loHelper.MakeField(m.t1, "@ref", "refId", "I",  4,0)
loHelper.MakeField(m.t1, "id", "id", "C",  10,0)
loHelper.MakeField(m.t1, "date", "date", "C",  10,0)
loHelper.MakeField(m.t1, "time", "time", "C",  5,0)

loHelper.MakeField(m.t2, "addr1","saddr1",  "C",20,0)
loHelper.MakeField(m.t2, "addr2","saddr2",  "C",20,0)
loHelper.MakeField(m.t2, "addr3","saddr3",  "C",20,0)
loHelper.MakeField(m.t2, "addr4","saddr4",  "C",20,0)
loHelper.MakeField(m.t2, "addr5","saddr5",  "C",20,0)
loHelper.MakeField(m.t2, "postcode","spostcode", "C",10,0)

loHelper.MakeField(m.t3, "addr1","daddr1",  "C",20,0)
loHelper.MakeField(m.t3, "addr2","daddr2",  "C",20,0)
loHelper.MakeField(m.t3, "addr3","daddr3",  "C",20,0)
loHelper.MakeField(m.t3, "addr4","daddr4",  "C",20,0)
loHelper.MakeField(m.t3, "addr5","daddr5",  "C",20,0)
loHelper.MakeField(m.t3, "postcode","dpostcode", "C",10,0)

loHelper.MakeField(m.t4, "when","when",  "C",20,0)
loHelper.MakeField(m.t4, "where","where",  "C",20,0)
loHelper.MakeField(m.t4, "actor","actor",  "C",20,0)

loHelper.MakeField(m.t6, "@id","childId",  "C",10,0)
loHelper.MakeField(m.t6, "length","",  "I",4,0)
loHelper.MakeField(m.t6, "breadth","",  "I",4,0)
loHelper.MakeField(m.t6, "width","",  "I",4,0)
loHelper.MakeField(m.t6, "weight","",  "I",4,0)

loAdapter.Tables.Add(m.t1, m.t1.XMLName)
loAdapter.Tables(1).ToCursor(.f.,'crsParent')
t1.ChildTable = m.t2
loAdapter.Tables(1).ToCursor(.f.,'crsSource')
t1.ChildTable = m.t3
loAdapter.Tables(1).ToCursor(.f.,'crsDestination')
t1.ChildTable = m.t4
loAdapter.Tables(1).ToCursor(.f.,'crsAction')
t1.ChildTable = m.t5
t5.ChildTable = m.t6
loAdapter.Tables(1).ToCursor(.f.,'crsChildren')


Define Class XMLAdapterUtils As Custom
  Procedure MakeTable(tcTableName)
    Local loTable As Xmltable
    loTable=Createobject("XMLTable")
    loTable.XMLName = Strconv(m.tcTableName,5)
    loTable.Alias=m.tcTableName
    Return loTable
  EndProc
  
  Procedure MakeField(toTable,tcXMLName, tcFieldName,tcFieldType,tnFieldLen,tnDecimals)
    Local loField As Xmlfield
    loField=Createobject("XMLField")
    loField.XMLName=Strconv(m.tcXMLName,5)
    loField.Alias=Evl(m.tcFieldName,m.tcXMLName)
    loField.XMLNameIsXpath = .T.
    loField.DataType=m.tcFieldType
    loField.MaxLength=m.tnFieldLen
    If Evl(m.tnDecimals,0) > 0
      loField.FractionDigits = m.tnDecimals
    Endif
    toTable.Fields.Add(loField,loField.XMLName)
  Endproc
Enddefine




Cetin Basoz

.Net has got better.Think about moving - check my blog:
My Blog


MongoDb Certified Developer
MongoDb Certified DBA


Support Wikipedia

ENTIRE THREAD

Efficient XML Parsing Posted by Paul Gibson @ 3/15/2013 4:05:13 PM
RE: Efficient XML Parsing Posted by James Frye @ 3/15/2013 7:21:49 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/15/2013 7:44:46 PM
RE: Efficient XML Parsing Posted by Ulhas Amrite @ 3/31/2013 5:43:14 AM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/31/2013 5:08:50 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/15/2013 9:14:02 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 3/15/2013 9:29:53 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 3/15/2013 9:47:44 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/15/2013 11:38:43 PM
RE: Efficient XML Parsing Posted by Srdjan Djordjevic @ 3/19/2013 5:24:20 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 12:47:51 PM
RE: Efficient XML Parsing Posted by Srdjan Djordjevic @ 5/14/2013 11:35:15 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 12:52:49 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/20/2013 3:37:02 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/20/2013 6:57:31 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/21/2013 5:06:20 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:15:33 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/21/2013 6:28:05 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:31:38 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:50:30 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/20/2013 9:30:55 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:35:12 PM
RE: Efficient XML Parsing Posted by Tamar Granor @ 3/22/2013 9:25:46 PM
RE: Efficient XML Parsing Posted by James Frye @ 5/11/2013 4:29:23 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 2:25:06 AM
RE: Efficient XML Parsing Posted by Paul Gibson @ 3/21/2013 1:34:45 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 10:19:56 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/8/2013 3:36:24 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/9/2013 1:07:22 AM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/9/2013 2:01:18 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/9/2013 2:29:08 PM
RE: Efficient XML Parsing Posted by Paul Gibson @ 5/15/2013 12:27:19 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/15/2013 1:11:27 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/9/2013 2:54:01 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/10/2013 1:23:41 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/10/2013 3:01:55 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 5/10/2013 3:10:19 AM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 5/10/2013 1:09:59 PM
RE: Efficient XML Parsing Posted by Rick Hodgin @ 5/10/2013 3:49:46 PM
RE: Efficient XML Parsing Posted by Cetin Basoz @ 3/21/2013 2:22:38 PM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/21/2013 10:47:28 PM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/28/2013 8:12:46 AM
RE: Efficient XML Parsing Posted by Russell Hill @ 3/29/2013 11:57:43 AM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/30/2013 6:43:29 PM
RE: Efficient XML Parsing Posted by Marco Plaza @ 3/29/2013 7:27:28 PM
RE: Efficient XML Parsing Posted by Jose Mendes @ 3/30/2013 6:44:07 PM