Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert text file into XML
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01659084
Message ID:
01659089
Vues:
60
I agree that FILETOSTR() should do the job and pretty fast. I just wanted to be sure that I am not missing something simple. And then I thought that most likely the XMLTOCURSOR() uses something similar to FILETOSTR() to get the file into a memory string anyway. So, I should be all set.
Thank you.


>Unless your file is absolutely massive, FILETOSTR() and a string insertion is going to be blazing fast - this is not something you should worry about unless you have multi-megabyte file that exceeds 16 megs. In that case you have to be careful as you won't be able to simply concat the header and footer to the string (you'd have to write out file as stream).
>
>What's more concerning though is - why is the data you are receiving invalid, non-parsable XML in the first place?
>
>+++ Rick ---
>
>>>>Hi,
>>>>
>>>>Say I have a text file saved on a drive that is almost like an XML. For example, the file will look like this:
>>>>
>>>><Record>
>>>>   <FirstName>John</FirstName>
>>>>   <LastName>Smith</LastName>
>>>></Record>
>>>><Record>
>>>>   <FirstName>Paul</FirstName>
>>>>   <LastName>Kelly</LastName>
>>>></Record>
>>>>
>>>>
>>>>So, as you can see, the file does not have the typical top line:
>>>>
>>>><?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
>>>>
>>>>And it does not have the Root Element, such as, for example:
>>>>
>>>><VFPData>
>>>></VFPData>
>>>>
>>>>
>>>>And I want to load this text file into a cursor using the code:
>>>>
>>>>XMLTOCURSOR( "MyTextFile.txt", Cur_Name, 512+8192)
>>>>
>>>>
>>>>I know that I can retrieve the string using STRTOFILE() and then add the top line and the Root Element. But that would be slow since the entire text file would have to be first loaded into a string. Is it possible to load the above text file into a cursor and add the top line and the Root Element on-the-fly?
>>>
>>>Hi, Dmitry
>>>
>>>You'll have to add the root element before the XML is parsed by the XMLTOCURSOR() function. You can make it with just one call, though:
>>>
>>>
>>>XMLTOCURSOR('<?xml version="1.0" encoding="windows-1252"?><Records>' + FILETOSTR("MyTextFile.txt") + '</Records>', "cur_name")
>>>BROWSE
>>>
>>
>>Thank you, Antonio. I guess I will have to "live" with FILETOSTR(). The good thing is the VFP is so fast that unless the MyTestFile.txt is huge, the loading will be pretty fast.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform