×
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

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

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

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

(OP)
I use cursortoxml() in two different applications like this to produce .xml files:

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

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

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

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

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

Mibosoft,

What are the ALIAS() of the current area in both cases?

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

(OP)
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:
sele A
use tablename
 
With this, the alias name without database name is used:
sele A
use tablename alias TABLEALIAS
 

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

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
https://www.doschke.name

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

(OP)
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 smile 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.

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