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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse XML files in 2.6 DOS ???

Status
Not open for further replies.

jabhawk2

MIS
May 11, 2007
9
US
I have been asked to parse XML files and pull elements out into a Foxpro DBF file. Is there a "simiple" method of doing this?

I do not have many rights to load utilites in this network and have to work with what I have.

Windows XP
MS Office
Foxpro 2.6 DOS

Jon
 
FPD 2.6 was made before XML was a gleam in anyones eye.

You are going to have to write the code for it.

David W. Grewe Dave
 
There is no "simple" way of doing this.

Back when EDI was the pre-XML standard, it was necessary to write a low-level routine using FOPEN(), FGET(), etc. commands to Parse the data out of the EDI file (a text file).

Now that XML is here, you will have to do the same approach with the XML file (it is really just a text file).

Developing the text parser can be a tedious process and you may have to build your code to pro-actively anticipate possible variations in the XML text (e.g. new fields, etc.), but when done, it should work well.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
[ ]
Here is a function that I use to find a line in a low level text file.



******************************
*
* Find line containing search string
*
******************************
*
* Finds next occurance of qStr in existing open file designated by qHandle.
* Automatically increments file pointer to end of last line processed.
* Always begins at current file pointer position in file.
* Continues until carriage return found or maximum bytes searched.
*
* SYNTAX:
* = LLFindLine(qHandle, qStr[, qLine[, qBytes]])
*
* ENTRY:
* qHandle N: File handle of file to be examined
* qStr C: String to find
* qLine C: "l" if left portion of line wanted
* C: "r" if right portion of line wanted
* Defaults to line containing qStr
* qBytes N: Number of bytes to search from current file position
* Defaults to 762 bytes
*
* EXIT:
*
* RETURNs:
* '' = String not found
* string = Part of file wanted
*
******************************

PARAMETER qHandle, qStr, qLine, qBytes
PRIVATE ALL LIKE z*

zfound = 0

IF TYPE('qBytes') <> 'N'
qBytes = 762
ENDIF

z = ASC(FORMAT(qLine))

DO WHILE EMPTY(zfound)

zthisline = FGETS(qHandle, qBytes)
IF FEOF(qHandle) AND EMPTY(zthisline)
EXIT
ENDIF
zfound = AT(qStr, zthisline)

ENDDO

DO CASE
CASE EMPTY(zfound)
zfound = ''
CASE z = 82 && Right
zfound = SUBSTR(zthisline, zfound)
CASE z = 76 && Left
zfound = LEFT(zthisline, zfound - 1)
OTHERWISE
zfound = zthisline
ENDCASE

RETURN zfound


The line in red uses one of my handy dandy functions which is way to long to put here. So, you will need to change that line to something that sets z to the ASCII value of qLine. Be aware that in the default mode that qLine can be .F., so a simple ASC() will not work.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Thnaks for the feedback. I had to write a parser to pull the needed data byte by byte. The file had no CR or LF so I had to scan each byte to find the tag starts and treat it as a new line then process previous line for wanted data.

Not pretty but did the job.

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top