Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
**********************************************************************
* Function : ConvertTableToXml
* Parameter: TblName
**********************************************************************
FUNCTION ConvertTableToXml
PARAMETER TblName
IF !USED(TblName) THEN
SELECT 0
USE &TblName
ENDIF
SELECT &TblName
LcXML =""
Add2XML([<?xml version ="1.0" encoding="windows-1252" standalone="yes"?>])
SELECT &TblName
*Open node
Add2XML([<] + TblName + [>])
NoFac =0
SCAN
NoFac = NoFac + 1
Add2XML ([<] + TblName + [>],1)
FOR i = 1 TO FCOUNT()
fld =LOWER(FIELD(i))
Add2XML( [<] + fld + [>] + ALLTRIM(TRANSFORM(EVALUATE(fld)))+[</] + fld + [>], 2)
ENDFOR
SELECT &TblName
Add2XML([</] + TblName + [>],1)
ENDSCAN
*Close Node
Add2XML([</] + TblName + [>])
*!* STRTOFILE(LcXML, "Data\XmlTest.XML")
RETURN LcXML
ENDFUNC
*- end of converttabletoxml
*~~~~~*
**********************************************************************
* Function : Add2XML
* Parameter: textto, indent
**********************************************************************
FUNCTION Add2XML
PARAMETERS Texto,Indent
Indent = IIF(EMPTY(Indent),0,Indent)
LcXML = LcXML + IIF(EMPTY(LcXML), "", CHR(13)) + REPLICATE(CHR(9), Indent) + Texto
RETURN
ENDFUNC
*- end of add2xml
*~~~~~*
*************************************************************************************
* Function : ConvertXmlToTable
* Requirments : This example uses the MSXML parser in ConvertXmlToTable function
* to move data from an XML document to a FoxPro table.
* The parser is available at: [URL unfurl="true"]http://msdn.microsoft.com/xml/default.asp[/URL]
*************************************************************************************
FUNCTION ConvertXmlToTable
*Create the parser object
oXML=CREATEOBJECT('msxml.domdocument')
*Gets the XML document.
*could improve this by passing the file name in by param
oXML.LOAD(GETFILE('xml'))
*** The following gives the basename of the XML document
*?oXML.DocumentElement.Basename
*** The following gives the number of nodes (or records)
*?oXML.documentelement.childnodes.LENGTH
* parses through each node element and adds it to the table.
WITH oXML.DocumentElement.ChildNodes
FOR iCount = 0 TO .LENGTH - 1
APPEND BLANK
FOR iChild = 0 TO .ITEM(0).ChildNodes.LENGTH - 1
lcVar = .ITEM(iCount).ChildNodes(iChild)
* Only replace if the node has a similarly named field in the table
REPLACE (lcVar.NodeName) WITH (lcVar.TEXT)
ENDFOR
ENDFOR
ENDWITH
BROWSE
ENDFUNC