Reading big xml file

Andrus

I need to read big xml file in Microsoft Visual FoxPro 9 SP2 desktop application. Created cursor result which contains desired columns and convert.xsl file to transform xml to format readably by xmltocursor.

Tried

source = CreateObject('MSXML.Domdocument')
stylesheet = CreateObject('MSXML.Domdocument')
resultDoc = CreateObject('MSXML.Domdocument')
resultDoc.validateOnParse = .t.
stylesheet.load('convert.xsl')
source.load( 'bigxml.xml' )
source.transformNodeToObject(stylesheet, @resultDoc)

* Exception code=E06D7363
IF XMLToCursor(resultDoc.xml, 'result', 8192 )=0

But got

Fatal exception 

Exception code=E06D7363 

at line

IF XMLToCursor(resultDoc.xml, 'result', 8192 )=0

and application terminates.

How to convert big xml file to cursor ?

XSL is:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes"/>

  <!-- this replaces root tag with VFPData which is required from CursorToXML to work properly -->
  <xsl:template match="/">
    <xsl:element name="VFPData">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <!-- this will denormalize XML data -->
  <xsl:template match="/ettevotjad/ettevotja">

    <xsl:element name="Document-Ariregister">

      <xsl:element name="nimi">
        <xsl:value-of select="nimi"/>
      </xsl:element>

      <xsl:element name="ariregistr">
        <xsl:value-of select="ariregistri_kood"/>
      </xsl:element>

      <xsl:element name="kmkr_nr">
        <xsl:value-of select="kmkr_nr"/>
      </xsl:element>

      <xsl:element name="ettevotja_">
        <xsl:value-of select="ettevotja_staatus"/>
      </xsl:element>

      <xsl:element name="asukoht_et">
        <xsl:value-of select="ettevotja_aadress/asukoht_ettevotja_aadressis"/>
      </xsl:element>

      <xsl:element name="asukoha_e2">
        <xsl:value-of select="ettevotja_aadress/asukoha_ehak_tekstina"/>
      </xsl:element>

      <xsl:element name="indeks_ett">
        <xsl:value-of select="ettevotja_aadress/indeks_ettevotja_aadressis"/>
      </xsl:element>
  
    </xsl:element>
  </xsl:template>

  <!-- to ommit nodes data -->
  <xsl:template match="text()">
  </xsl:template>

  <!-- to work over every node -->
  <xsl:template match="*">
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>
mplaza

Here is a solution using mxml.6.0., no need for xs file:

* requires msxml.6.0! ( https://www.microsoft.com/es-es/download/details.aspx?id=3988 )
*
Parameters fileName,xPath

fileName = "D:\Data\Xml\ettevotja_rekvisiidid_2021-01-27.xml"
xPath = '/ettevotjad'

xPath = RTRIM(m.xPath,1,'/')

Private All

If Type('_screen.oxml') = 'U'

    _Screen.AddProperty('oXml',Createobject('msxml2.domDocument.6.0'))

    Wait 'loading document...' Window Nowait

    With _Screen.oXml As msxml.DOMDocument
        .Load(Fullpath(m.fileName))
        Wait Clear
        If .parseError.errorCode # 0
            Messagebox(.parseError.reason,16)
            Return
        Endif
    Endwith

Endif

oXml = _Screen.oXml

Close Tables All

nsteps = 500
tini = Seconds()
Set Escape On

x =  1

DO WHILE .t.

    subset = oXml.selectNodes(Textmerge(m.xPath+'/*[ position() >= <<m.x>> and position() < <<m.x+m.nsteps>> ]'))

    IF subset.length = 0
        EXIT
    ENDIF

    cXml = ''

    For Y = 1 To subset.Length
        m.cXml = m.cXml + subset.Item(m.y-1).XML
    ENDFOR
    
    x = m.x + subset.Length

    Wait Textmerge('<<m.x-1>> records  << (m.x-1) / (SECONDS() - m.tini) >> records/sec ') Window nowait
    
    cXml = '<xml encoding="windows-1252">'+m.cXml+'</xml>'

    Xmltocursor(m.cXml,'xmlImport',Iif(Used('xmlImport'),4+8192,0))


ENDDO



Browse Normal Font 'consolas,8'



Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related