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 this XML file to DBF file 3

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
526
Brasil
How is the simplest way to put this FRIENDS.XML file into a DBF file ? Im using Visual FoxPro 9.
Thanks,
Tony

FRIENDS.XML file:

<Telephones>
<Person>
<Name>John Doe</Name>
<Phone>784-9876</Phone>
</Person>
<Person>
<Name>Mary</Name>
<Phone>814-0234</Phone>
</Person>
<Person>
<Name>Paul Curtis</Name>
<Phone>513-0001</Phone>
</Person>
</Telephones>
 
Hi Olaf !

I wrote the following command in the command window (FRIENDS.XML is in the current directory):

XMLTOCURSOR(FRIENDS.XML)

And I got this error:
"Alias 'FRIENDS' is not found."

Thanks,
Tony
 
You have not fully defined the function operators.

Your XML data must be in a string variable and you must define the output Cursor.

Look into your VFP9 Help for XMLTOCURSOR() for detailed info on how to use the function.

Good Luck,
JRB-Bldr
 
Something like this should do the trick:

Code:
XMLTOCURSOR("Friends.xml", "csrResult", 512)

That should convert the data in the file to a cursor named csrResult.

If you want to end up with a physical DBF, rather than a cursor, them create the table and copy the data from the cursor to it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike has shown you the correct syntax. For a single command this can easily be lokked up in the VFP online help. F1 is your friend.

Bye, Olaf.
 
Ok Mike, XMLTOCURSOR("Friends.xml", "csrResult", 512) seems to have generated 3 records into a cursor.
But how to access these data recorded in the cursor ? (I have never used data in cursors).
Thank you.
 
A cursor behaves the same as a dbf. It is a dbf. To store that data as dbf, simply do

Code:
XMLTOCURSOR("Friends.xml", "csrResult", 512)
select csrResult
COPY TO friends.dbf

Bye, Olaf.
 
A cursor is just like a table. Any command that works on a table works exactly the same on a cursor (there are some exceptions, but they don't affect your situation).

So, to access the records in the cursor, you can browse it, you can scan it (in a SCAN / ENDSCAN loop), you can use the cursor as the control source for a form or a report, or whatever else you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Dear M.Gagnon, Olaf, M.Lewis, JRB,

Ok, I got the result I needed from your answers.
I read the XML file into a cursor, and copied the cursor to a DBF table.

Thank you very much for your valuable help !

Tony
P.S.: I have lots of books about VFP (from version 6 to 9) and for days I had not found a useful and simple example like you provided me here.
 
Tony,

I can imagine a book is seldom answering a concrete question, books are to get an overview. But once you're pointed to a certaain function the reference section is telling you everything about it's syntax and use cases.

See TOC of the chm help, main chapter "Reference", sub chapter "Language Reference", sub sub chapters "Functions" and "Commands". Besides that selecting a command in a prg or in the command window and pressing F1 while that keyword is selected will forward you to the related topic. Nice feature of the help. Take that for futire reference.

As you don't know a cursor is a dbf you rather lack very basic knowledge about foxpro. I'm tempted to ask, if you read one of the books from cover to cover.

I don't now how long or how short you're using VFP. I tend to not treat anybody as a total beginner, even if he's describing himself as technical user instead of programmer.

Sorry, you indicate you're satisfied with the final outcome, but also justify asking the question, by telling you alredy did your best to answer it yourself.

Indeed that aspect is not needed as in other newsgroups and forums I know, but this is an aspect true for the whole foxpro community.

While I indicated and still do, that you should read on XMLTOCURSOR() and COPY TO to get this into your personal knowledgebase, I did point you to that topic.

It's no question that finding out this function is the hardest part, every single comand, class, function is buried in lot's of others and hard to find, if you don't know the language at all. So I gave you xmltocursor, which limits your search from reading all the books and the vfp help to one single topic. Sorry not knowing you're having quite no knowlegde about VFP at all, so you need more than that pointer.

After all that, please feel welcome, no offense. It's just less and less usual to see someone learning a discontinued language.

Bye, Olaf.
 
Hi Olaf !

I've programming with VFP since 2002 (now I use VFP 9). Indeed I have never user cursors, I tend to use temporary phisical DBF files. I will try to use cursors from now on.

I have also been surprised that I couldn't find myself how to import XML files, even from VFP Help. I saw lots of examples in the Hentzenwerke books (for example, in MegaFox: 1002 Things... , says about using SAX or DOM to acomplish the task!) but none as simple and direct as I found here in this forum.

Thank you for your note.

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top