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

When does Cursortoxml() include the dbc() name in the XML output? 1

Status
Not open for further replies.

mibosoft

Programmer
Jul 23, 2002
106
SE
I use cursortoxml() in two different applications like this to produce .xml files:

[pre]
select A
set fields to field1,field2
cursortoxml(0,"L_XML",1,32)
strtofile(strconv(L_XML,9),"outfile.xml")
set fields off
[/pre]

In application 1, the table names are prepended with the database name like this in the produced xml:
[pre]<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<VFPData>
<dbname_tablename>
<field1>S</field1>
...[/pre]

In application 2, the database name is not included:
[pre]<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<VFPData>
<tablename>
<field1>S</field1>
...[/pre]

Can anyone explain how to control this? I want the dabase name always to be included.
Thanks'
 
Mibosoft,

What are the ALIAS() of the current area in both cases?
 
Thank you for the hint atlopes! It showed to be due to that if I open a table like this without an alias name, the database name is prepended in the xml:
[pre]sele A
use tablename
[/pre]With this, the alias name without database name is used:
[pre]sele A
use tablename alias TABLEALIAS
[/pre]
 
I can't confirm. You say the DBC name gets into the XML when you don't actively give an alias name. I don't see that.

If I open a table (say orders) of a database (say the Northwind sample database), the workarea (ALIAS()) name is "orders", not "northwind_orders". And the XML also has "orders" tags.

It's simply the alias name. And if you don't use the ALIAS clause of the USE command and don't use the long name convention database!table, you get the file name as the alias name.

CURSORTOCML simply takes the alias name of the workarea. So unless you don't actively prepend the DBC name (JUSTSTEM(DBC()) to the alias name, your XML output has no clue of the database origin.

Closing this with a demonstration using differing physical (file) names and logical names for both db and table:
Code:
Clear 
Cd GetEnv("TEMP")

Create Database '1st database'
Create Table 'table1 file.dbf' Name "my table1" (id1 integer)
Create Table '2nd table file.dbf' Name "my table2" (id2 integer)
Use
Close Databases

Open Database '1st database'
ADatabases(laDBC)
? laDBC[1,1]
? Dbc()

? '-------'

* automatically determiend alias name
Select 0
Use 'table1 file'
? Alias()
? Dbf()

? '-------'

* automatically determiend alias name
Select 0
Use '1st database!my table1' again
? Alias()
? Dbf()

? '-------'

* automatically determiend alias name
Select 0
Use '2nd table file'
? Alias()
? Dbf()

? '-------'

* manually specified alias name
Select 0
Use 'my table1' Alias _1st_database__my_table1 again
? Alias()
? Dbf()

You can clearly see why everybody avoids naming DBF files starting with a digit. The file system allows that but the automatic alias name of a USE will just take the workarea name (C for workarea 3, W2164 if you first SELECT 2164).

CursorToXML will always pick up the alias name, no more, no less.

What this also shows: Even if you'd give all your DBC tables long table names that prefix the database name, automatic alias names of workareas don't orient themselves mainly after the internal long table name within the DBC. When you use the DBF files by their file name you still have filenames as alias names, as far as that works (spaces are converted to underlines and of course path and file extension are stripped off).

Now, if you have a problem with the XML you could also use Textmerge to be in full control of the tags and namespace and inline schema or XSD file. For example, it takes very few changes you could do with STRTRAN in the variable before using STRTOFILE, to make that XML compatible for usage in .NET languages. I can't tell from the top of my head, but it would mean to replace <VFPData> and </VFPData>, either simply remove this or replace it with a better-suited XML header.

Oh, and last not least wwXML existed before this VFP internal commands, it did things better and continues to do so and continues to work. And by the way, CURSORTOXML has no dependencies to MS XML libraries/DLLs, but XMLToCursor depends on MSXML3, XMLAdapter, XMLTable and other classes depend on MSXML4.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Olaf,
You are absolutely right. It's the alias name that goes into the XML and if ALIAS is not used, you get the file name. I got confused and forgot that all tables in my database start with the database name :) All this was discovered when I built a separate executable to do all XML handling without slowing don the main application.

Thank you for a very detailed explanation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top