Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Marco Plaza
  Where is Marco Plaza?
 Caracas
 Venezuela
 Marco Plaza
 To: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 Tags
Subject: RE: Efficient XML Parsing
Thread ID: 372993 Message ID: 373304 # Views: 75 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: XML
Date: Thursday, March 21, 2013 5:06:20 AM         
   


> 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

Great example Cetin. Finally I can understand the use for xpath expressions on the xmladapter,
though some areas are still obscure science.

Can you please explain this:

you state that the xmlName is converted to unicode, the alias name does not,and both are equal:
> loHelper.MakeField(m.t1, "id", "id", "C", 10,0)

here you use a different name for destination, not converted:
> loHelper.MakeField(m.t2, "addr2","saddr2", "C",20,0)
> loHelper.MakeField(m.t3, "addr1","daddr1", "C",20,0)

here the xmlName is converted to unicode, and the alias name too by the evl() function:
> loHelper.MakeField(m.t6, "length","", "I",4,0)

took my attention the fact that you got only 1 table ( loadapter.tables(1) ) and got the child tables from it!

when I use respectnesting option to make nested xml I get 4 tables.. for example:



Close Data
Do createXML
Close Data
do xml2Cursors

*----------------------------------------
Procedure createXML
*----------------------------------------
Close Databases

Create Cursor mycursor(Id c(9),Name c(30),secName c(20),gender c(1),address c(40),state c(35),zipcode c(5),birthdate d(8),weight N(5,1),Height N(5,1),Notes c(254))

Insert Into mycursor ;
	( Id,Name,secName,gender,address,state,zipcode,birthdate,weight,Height,Notes ) ;
	VALUES ;
	( '123','JOHN','SMITH','M','4405 NW','FLORIDA','33105',{^2012/03/26},54.1,152.3,'primer control')


Index On Id Tag Id

Use Dbf() In 0 Again Alias patient
Use Dbf() In 0 Again Alias personalData Order Id
Use Dbf() In 0 Again Alias address Order Id
Use Dbf() In 0 Again Alias Attributes Order Id

Set Relation To Id Into personalData In patient
Set Relation To Id Into address In patient Additive
Set Relation To Id Into Attributes In patient Additive

Set Fields Global

Select patient
Set Fields To Id

Select personalData
Set Fields To Name,secName,gender,birthdate

Select address
Set Fields To address,state,zipcode

Select Attributes
Set Fields To weight,Height,Notes

oxml = Createobject('xmladapter')


With oxml As Xmladapter

	.RespectNesting= .T.
	.XMLSchemaLocation = 'x:\test.xsd'
	.AddTableSchema('patient',.F.)
	.AddTableSchema('personalData',.T.)
	.AddTableSchema('address',.T.)
	.AddTableSchema('attributes',.F.)
	.ToXML('test.xml',,.T.)

messagebox('TABLES COUNT:'+transform(.TABLES.COUNT,'99'),0)
Endwith

Modify File test.XML


*---------------------------------------------
Procedure xml2Cursors
*---------------------------------------------

oxml = Createobject('xmladapter')

With oxml As Xmladapter

	.RespectNesting= .T.
	.XMLSchemaLocation = 'test.xsd'
	.LoadXML('test.xml',.T.)

	For Each tabla In .Tables

		tabla.ToCursor()

	Endfor

Endwith


SET



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