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: Srdjan Djordjevic
  Where is Srdjan Djordjevic?
 Limassol
 Cyprus
 Srdjan Djordjevic
 Tags
Subject: RE: Efficient XML Parsing
Thread ID: 372993 Message ID: 373261 # Views: 121 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: XML
Date: Wednesday, March 20, 2013 12:47:51 PM         
   


> >
> > Are there any other methods I should try or should I look at my own inefficient method using MSXML and see if I can drastically improve it?
>
>
> Are you importing or exporting data from/to some outside xml source/target or you just need to parse
> tables data within layers/tiers of foxpro application itself ?
>
> If later then there is solution (parsing tables as objects) which does not even require XML
> and it is much much faster. (with few limitations)
> See
>
> http://www.universalthread.com/ViewPageNewFAQ.aspx?ID=29297
>
>
> HTH
> Sergio
> www.report-sculptor.com

Hey Srdjan,
How you doing. I have a similar 'dataset maker' to pass data between sessions (code below). I think Paul was asking because he had an XML to start with (assumption). Otherwise maybe the easiest way to create a nested XML (and then get back tables) would be by using XMLAdapter (I will post samples now). Take care.

* DatasessionPass.prg
***********************************************
* Sample code using DataSet class
***********************************************
Local loSession1, loSession2
* Create 1st private datasession
loSession1 = Createobject('Session1')
loSession1.SomeQueries() && run some queries

loSession2 = Createobject('Session2')
loSession2.GetTheDataAndBrowse(loSession1) && transfer data from session1


Define Class session1 As Session
  DataSession = 2 && Private

  Procedure SomeQueries

    Select * From (_samples+'data\customer') Where country = 'USA' Into Cursor crsUSA
    Select ord.* From (_samples+'data\orders') ord ;
      INNER Join crsUSA On crsUSA.cust_id == ord.cust_id ;
      ORDER By ord.cust_id, ord.order_date ;
      INTO Cursor crsUSAOrders ;
      nofilter

  Endproc

  Procedure GetDataCursors( tcAliasList, tcAsAliasList )

    If Empty(m.tcAsAliasList)
      tcAsAliasList = m.tcAliasList
    Endif

    Local laAlias[1], laAsAlias[1]
    Local oDataSetPacker As 'DataSet' Of Fullpath('DatasessionPass.prg')
    Local ix, lcAlias, lcAsAlias
    oDataSetPacker = Newobject('DataSet',Fullpath('DatasessionPass.prg'))


    Alines(laAsAlias, m.tcAsAliasList,1,',')
    For ix = 1 To Alines(laAlias, m.tcAliasList,1,',')
      lcAlias   = laAlias[m.ix]
      lcAsAlias = Iif(m.ix > Alen( laAsAlias ), laAlias[m.ix], laAsAlias[m.ix] )
      oDataSetPacker.AddTable(m.lcAlias, m.lcAsAlias)
    Endfor
    Return oDataSetPacker
  Endproc

Enddefine

Define Class session2 As Session
  DataSession = 2 && Private

  Procedure GetTheDataAndBrowse(toOtherSession)
    Local loDataSet
    loDataSet = toOtherSession.GetDataCursors( ;
      'crsUSA, crsUSAOrders', 'crsCustomer,crsOrders' )
    loDataSet.RestoreDataset(This.DataSessionId)
    Select crsCustomer
    Browse
    Select crsOrders
    Browse
  Endproc

Enddefine
***********************************************
* Sample code using DataSet class
***********************************************



* DataSessionPass.prg
**************************************************************************************
** Dataset class to pack given cursors into an object to pass between data sessions
**************************************************************************************
Define Class DataSet As Custom
  TableCount = 0
  DataSessionId = 0
  Dimension TableInfo[1]

  Procedure Init
    This.DataSessionId = Set("Datasession")
  Endproc

  Procedure AddTable(tcAlias, tcAsAlias)
    Local Array aStruc[1],aStripped[1]
    Local ix
    Afields(aStruc,m.tcAlias)
    Dimension aStripped[ALEN(aStruc,1),5]
    For ix = 1 To Alen(aStruc,1)
      aStripped[m.ix,1] = aStruc[m.ix,1]
      aStripped[m.ix,2] = aStruc[m.ix,2]
      aStripped[m.ix,3] = Iif(aStruc[m.ix,2]='V',Min(aStruc[m.ix,3],254),aStruc[m.ix,3])
      aStripped[m.ix,4] = aStruc[m.ix,4]
      aStripped[m.ix,5] = aStruc[m.ix,5]
    Endfor

    This.TableCount = This.TableCount + 1
    Dimension This.TableInfo[this.TableCount]
    This.TableInfo[this.TableCount] = Createobject('Custom')
    With This.TableInfo[this.TableCount]
      .AddProperty('aStructure[1]')
      .AddProperty('aRecords[1]')
      .AddProperty('Records')
      .AddProperty('Alias',m.tcAlias)
      .AddProperty('AsAlias', Iif(Empty(m.tcAsAlias),m.tcAlias,m.tcAsAlias) )

      Acopy(aStripped, .aStructure)
      Select * From (m.tcAlias) Where !Deleted() Into Cursor __crsTemp__ nofilter
      .RecordS = Reccount()
      If .RecordS > 0
        Dimension .aRecords[RECCOUNT()]
        Scan
          Scatter Name .aRecords[RECNO()] Memo
        Endscan
      Endif
      Use In '__crsTemp__'
    Endwith
  Endproc

  Procedure RestoreDataSet(tnDataSessionID,tlRestoreIfNotUsed) && restore all with saved aliases
    Local lnCurrentSession,ix
    lnCurrentSession = Set("Datasession")
    For ix = 1 To This.TableCount
      This.Obj2Cursor( This.TableInfo[m.ix].Alias, '', m.tnDataSessionID,m.tlRestoreIfNotUsed )
    Endfor
    Set DataSession To m.lnCurrentSession
  Endproc

  Procedure Obj2Cursor( tcStoredAlias, tcAlias, tnDataSessionID,tlRestoreIfNotUsed )
    Local ix,jx
    If !Empty(m.tnDataSessionID)
      Set DataSession To m.tnDataSessionID
    Endif
    For ix = 1 To This.TableCount
      With This.TableInfo[m.ix]
        If Upper(.Alias) == Upper(m.tcStoredAlias)
          tcAlias = Iif(Empty(m.tcAlias), .AsAlias, m.tcAlias )
          If (m.tlRestoreIfNotUsed And Used(m.tcAlias))
            Select (m.tcAlias)
          Else
            ** Check array for any c(255)
            Local lnArrElem
            For lnArrElem=1 To Alen(.aStructure,1)
              If .aStructure[m.lnArrElem,3] = 255 And .aStructure[m.lnArrElem,2]='C'
                .aStructure[m.lnArrElem,3] = 254
              Endif
            Endfor
            Create Cursor (m.tcAlias) From Array .aStructure
            For jx = 1 To .RecordS
              Append Blank
              Gather Name .aRecords[m.jx] Memo
            Endfor
            Exit
          Endif
        Endif
      Endwith
    Endfor
    Set DataSession To This.DataSessionId
  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