×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

low level file functions to parse an xml
3

low level file functions to parse an xml

low level file functions to parse an xml

(OP)
I am using Foxpro for DOS 2.6 (with vdos emulator) to open an xml file (utf 8 type)
(believe it or not and I will eventually have to move this prototype to a modern language - but I know what I know !)

The file does not appear to have any unusual characters
When I try to append it to a dbf file sdf it gives the error - line too long

In this file the information I want to capture is about 200 characters long I estimate
It starts with the characters <row/> on each occasion

I gather that I would do this using the command
x=fopen("input.xml") to get a file handle
then use the fseek function to look for the <row/> within a do while not feof() loop
then collect the information into another file output.txt
and close everything

My problem is that I don't know the specifics of these low level file functions and my mac rubel book is short on specifics

If you are smart or have grey hair or both Your help would be appreciated

I cannot post the file as it contains confidential p-atient information

thanks

franklin

RE: low level file functions to parse an xml

(OP)
Tamar , I have been following your work for longer than either of us would like to admit. Thanks for that technical bulletin. I have looked around the internet and its the details/syntax of the specific commands that are screwing me up that I can't find and I dont have my tech reference any more so when I try to run them they don't work. Its also hard to close the file once its opened and then I get the -1 error

I am sure that someone out there has a seek function and then copy to a text file
already in their pocket

I found the following on the internet but was unable to adapt it as it calls a function called format that the developer did not provide
and only does part of the job



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

RE: low level file functions to parse an xml


Since you are using fox dos, the next procedure is a start for you to continue processing as needed ,
- assuming "row" is your delimiter.

Note: It's unadvised to read xml using string functions. Check nfXml on vfpx and vfp native functionallity.

CODE

filename = 'temp.xml'

cstartdelimiter = '<rows>'
cenddelimiter = '</rows>'

*-------------------------------------


fhin = Fopen(m.filename)

If m.fhin < 0

  wait 'error opening '+m.filename window

else


  outfile  = 'tempFile.txt'

  fhout = Fcreate( m.outfile )

  Do While .T.

    cline = Fread( m.fhin, 10000 )

    If Empty(m.cline)
      Exit
    Endif

    cline = Chrtran( m.cline, Chr(13)+Chr(10)+Chr(9),'' )
    cline = Strtran( m.cline, m.cenddelimiter, m.cenddelimiter+Chr(13)+Chr(10))

    Fwrite( m.fhout, m.cline )

  Enddo

  Fclose( m.fhin )
  Fclose( m.fhout )

  Modify File &outfile

Endif 

Marco Plaza
@nfoxProject
https://www.github.com/nftools

RE: low level file functions to parse an xml

Quote:

I have looked around the internet and its the details/syntax of the specific commands that are screwing me up that I can't find and I dont have my tech reference any more

I doubt that you will find any useful on-line documentation for FoxPro for DOS. But all the low-level file functions are also supported in Visual FoxPro. Here is a link to the VFP documentation: https://docs.microsoft.com/en-us/previous-versions...

Use this to look up FOPEN(), FSEEK(), FGETS(), etc. and you should find the information you need.

Quote:

I found the following on the internet but was unable to adapt it ....

Blindly copying and pasting stuff you have "found on the internet" is not the way to solve a problem - and not the way to learn FoxPro. It is just laziness. You need to understand what you have found. It is then up to you to apply that understanding to your own problem.

I'd also argue against pasting other people's code in this forum without some sort of credit to the author or acknowledgement of the source.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close