Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert dbf to xml

Status
Not open for further replies.

borsker

Programmer
Jul 24, 2002
147
US
i am trying to convert a dbf to an xml file, and i do not even know where to start. is there somewhere i can look for this, or is this an easy code to use?
 
There are a number of previous postings in this forum concerned with XML. Use the Search function and you will find these to reference.

Additionally if you go to forum1253 you will also be able to do a Search for XML and find a number of previous postings there as well.

See if those answer your questions, if not, feel free to come back with your remaining questions.

Good Luck,
JRB-Bldr
 
The problem is everyone is posting problems when translating and not how to translate. I am sorry about this. the version of vfp i have does not see a help file and all our books were water logged in the hurricane. is there a lot of code that goes on with it?
 
What version are you using? In recent versions, CursorToXML() is your best bet.

Tamar
 
WE use, in VFP^ the following three procedures to get DBF to XML and back again.

Code:
**********************************************************************
* 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

So if you call the first of these with the alias of the table in question, which should be open. It should do the trick for you. I would also recommend updating this code to enable you to specify the output destination and to check if the table supplie dis open. I'll leave that up to you. This is just the basics. This does need MSXML4 installed, just search MSDN for this if you haven't go it already.
Cheers
Nathan
 
ok i am lost. i am not sure how to get this thing how to work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top