XML and Foxpro

fmoore0001
fmoore0001 used Ask the Experts™
on
I have a client with a need for XML output  from Foxpro.  I have played with it a bit in the past- enough to generate something useful, but he needs a specific header in his XML file and I have not figured out how add it:

In the past I have made simple XML files from a Cursor that generate data in this fashion:
<?xml version="1.0"?>
 -<Tablename>
       -<Field1>datum1</Field1>
       -<Field2>datam2</Field2>
 -</Tablename>

Foxpro will do that just with the CURSORTOXML() command.  But, this time I need to add some sort of a header defination:

<?xml version="1.0"?>
   -<Mcr reportingDate="2011-01-01" periodType="MCRYTD" year="2011" type="S">
        -<Tablename>
            -<Field1>datum1</Field1>
            -<Field2>datam2</Field2>
       -</Tablename>
  -</mcr>

And I am lost how to do this.  Any ideas, or useful references to a how to guide on this?

Frank
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CaptainCyrilFounder, Software Engineer, Data Scientist
Commented:
I write my own exporters.

cXML = [<?xml version="1.0"?>]
cXML = cXML + [<Mcr reportingDate="] + DTOS(DATE()) + [" periodType="MCRYTD" year="2011" type="S">]
...
= STRTOFILE(cXML,'MyXMLExport.xml')
Olaf DoschkeSoftware Developer

Commented:
Either that or

1. create first xml with CURSORTOXML() into a string variable (see parameter cOutput, set it as the variable name)
2. manipulate the string, eg stuff the new header into it via the STUFF() function, STUFF at the position right before the <tablenam> tag.
3. write the string to an xml file.

Bye, Olaf.
Maybe the most important hint is: You may ignore indentation in XML file and the output can look like this:

<?xml version="1.0"?>
<Mcr reportingDate="2011-01-01" periodType="MCRYTD" year="2011" type="S">
<Tablename>
        <Field1>datum1</Field1>
        <Field2>datam2</Field2>
</Tablename>
</mcr>


So, generate the XML in VFP, extract the first meta tag, enclose the rest by your new heading and return the meta tag back to top...
CaptainCyrilFounder, Software Engineer, Data Scientist
Commented:
Another way it to put the non-data information in one variable and then you change the fields as follows:

cXML = [...] + [<Mcr reportingDate="<Year>-<Month>-<Day>" periodType="MCRYTD" year="<Year>" type="S">] + [...]

or you can read it from a file:

cXML = FILETOSTR('myheaderxml.xml')
cXML = STRTRAN(cXML,'<Year>',TRANSFORM(YEAR(dDate)))

You can export the data part the same way.
cXML = STRTRAN(cXML,'<Data>',cDataXML)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial