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!

help with cursortoxml

Status
Not open for further replies.

JudyBarer

Programmer
Jan 13, 2004
23
US
I am using VFP 8.0 I need to create an xml document. I used cursortoxml which works ok. The only thing I need to do is to change the root node from <VFPData> to
<FullAdd Agency=Star-K>. I tried to write the xml to a memvar and then use strtran to make the character changes but it does not work. I am able to use the AT function to locate VFPDATA string but then when I try to use STUFF to replace the string it does not work. It does absolutely nothing to the memvar. I also tried having cursortoxml write to a file and then use filetostr to convert to memvar but this does not work either. It seems to me that there are control characters in the XML that I can not see and are somehow preventing this from working. Any help would be much appreciated.
 
Does the following work when you execute it?

Code:
Does the following work when you execute it?

CREATE CURSOR crsTemp (name c(7))
INSERT INTO crsTemp (name) VALUES ("Craig")
INSERT INTO crsTemp (name) VALUES ("Bob")
INSERT INTO crsTemp (name) VALUES ("Judy")
INSERT INTO crsTemp (name) VALUES ("Sue")
INSERT INTO crsTemp (name) VALUES ("Wiliam")
INSERT INTO crsTemp (name) VALUES ("Daniel")

CURSORTOXML("crsTemp", "cXML")
cXML = STRTRAN(cXML, "<VFPData>", "<FullAdd Agency=Star-K>")
cXML = STRTRAN(cXML, "</VFPData>", "</FullAdd Agency=Star-K>")
?cXML

...if it does, then how is the code you are using different?

boyd.gif

SweetPotato Software Website
My Blog
 
XMLtoCursor is generally only suitable for simple XML needs. A better solution is to use the XmlAdapter object. I made some comments in the VFP Web Related Issues forum1253, see thread1253-874466.
 
I tried the simple case above of creating the cursor and then doing the strtran and that worked. So I tried a simple case myself with my own data.

The following code worked fine

SELECT mfg.company_name FROM vaad!mfg;
into CURSOR txml

CURSORTOXML("txml", "cXML")
cXML = STRTRAN(cXML, "<VFPData>", "<FullAdd Agency=Star-K>")

The following code did not work
SELECT mfg.company_name , items.item_name;
FROM vaad!mfg ;
INNER JOIN vaad!items ;
ON mfg.company_id = items.company_id;
WHERE (ALLTRIM(UPPER(items.company_id)) =="APPLE";
OR ALLTRIM(UPPER(items.company_id)) == "XENA";
OR ALLTRIM(UPPER(items.company_id)) == "NOVICK";
OR ALLTRIM(UPPER(items.company_id)) == "J&K INGR");
AND ALLTRIM(UPPER(items.kosher_status)) == "CERTIFIED";
AND ALLTRIM(UPPER(company.dir_web_status)) == "COMPLETE LISTING";
AND product.not_for_web = .f.;
AND product.appear_on_loc = .t.;
into cursor txml ;
GROUP BY items.item_num

Also instead of the first line in the xml having <VFPDATA> it had <VFPDATA\> Does that mean something?
 
I also tried using the xmladaptor and here is the code I used
lcDataSetTag = "FullAdd Agency=Star-K"
lcRecordTag = "Products"
loXad = CreateObject("XMLAdapter")
loXad.AddTableSchema('Products', .T., STRCONV(lcRecordTag,12))
lconvtag = STRCONV(lcDataSetTag,12)
loXad.XMLName = lconvtag
loXad.XMLSchemaLocation = ""
loXad.UTF8Encoded = .T.
loXad.RespectCursorCP = .T.
loXad.ToXML("f:\stardata\test\reports\newmxl.xml", "", .T.)

The line loXad.XMLName = lconvtag generates an error of
"Function argument value type or count is invalid"
If I remove the space from the lconvtag string it does not generate an error. Is there a way around this? I need the space

Thanks
Judith
 
I guess there is some issue with translating certain characters to unicode because even though the code
below does not generate the error of function argument invalid , when I try to read the xml generated in ie it does not work. However when I replace "FullAddAgency=Star-K"
with "FullAddAgencyStar-k" it is able to read it.
lcDataSetTag = "FullAddAgency=Star-K"
lcRecordTag = "Products"
loXad = CreateObject("XMLAdapter")
loXad.AddTableSchema('Products', .T., STRCONV(lcRecordTag,12))
lconvtag = STRCONV(lcDataSetTag,12)
loXad.XMLName = lconvtag
loXad.XMLSchemaLocation = ""
loXad.UTF8Encoded = .T.
loXad.RespectCursorCP = .T.
loXad.ToXML("f:\stardata\test\reports\newmxl.xml", "", .T.)


Any ideas on that?
Thanks
Judith
 
Perhaps your XML parsing error comes from the fact that:
< FullAdd Agency=Star-K >

is not a valid XML tag... all values on tag attributes must be in quotes... so change it to:

< FullAdd Agency="Star-K" >

(of course, also delete the spaces I added after < and before > so the tags wouldn't be invisible in your browser)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top