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:
01659088
Vues:
61
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.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform