StarGateSG-1 Posted April 27, 2006 Share Posted April 27, 2006 Hello,Can some one point in the direct of source code to convert text files to xml files.Thank you Link to comment Share on other sites More sharing options...
boen_robot Posted April 27, 2006 Share Posted April 27, 2006 Add some elements around the sections of the text you want to extract separately, perhaps even group them in another element by some sort of criteria, add the XML prolog and possibly some encoding to it. If your text has one of the special entities, you should also mark it in CDATA. Save the file with XML extension and you're done. Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted April 28, 2006 Author Share Posted April 28, 2006 Sorry,I should have been more specific.I need some one to point me in the direction of source code, or tutorials to convert text files to xml files at the press of a button. I am writing a program for my school, which creates text files from our data system and I want to put them into xml files. Keep in mind I won;t be there to do it by hand. It must be automated.Any language would do, I would perfer something web based, but non would be fine.Thank you. Link to comment Share on other sites More sharing options...
Little Goat Posted April 28, 2006 Share Posted April 28, 2006 well, there are a lot of options in XML, if you know what the general format of the text will be, and if it always needs the same elements, that would make it a lot easier.LG Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted April 28, 2006 Author Share Posted April 28, 2006 Hello,Yes, I know what the text files are like and yes they all require the same tags over an over.does anyone have a link to a source code or tutorial to help me with with this.Thank you! Link to comment Share on other sites More sharing options...
Little Goat Posted April 28, 2006 Share Posted April 28, 2006 well, that might work, can you give me the general format of the text files?It could probably be done with php, using the explode statement and a few other things.LG Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted April 28, 2006 Author Share Posted April 28, 2006 Sure,the format is in fields. eg:123456789123456789123456789123456789firstname lastname age ###### Those arn't fields I would use but they are the most common, becasue this project is through the school, the data is private so It is hard to find the actuaclly field lengths I need, atm.Like that with space alotted for each section, I need a reference more than it done for me.Thank you. Link to comment Share on other sites More sharing options...
Little Goat Posted April 28, 2006 Share Posted April 28, 2006 do you know PHP?that is what I would use, but that might just be that I don't know anything better .so anyway, look up the file_get_contents() function here: http://us3.php.net/manual/en/function.file-get-contents.phpopen your file with that, and have the text fields seperated with | or something else, then use explode(): http://us2.php.net/explodethen enter the xml tags in and save it using the fopen() fwrite() and fclose() statements. (google php fopen())LGEdit: if you need it more specific, I can do that too. Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted May 1, 2006 Author Share Posted May 1, 2006 I might try that,What about VB, I have seen some good results with that, but I don;t really know VB. Link to comment Share on other sites More sharing options...
boen_robot Posted May 1, 2006 Share Posted May 1, 2006 If by VB you mean VBScript, it's a client side scripting language. It can't generate files, but I think it might be able to turn a text into XML and show it as one. Still, you need to reuse that XML data somewhere right? That's where VBScript fails.If you mean Visual Basic... well it could, but it's not web based technology, therefore inaccessable from a site.As far as I know, you could use VBScript on the server side with ASP(.NET?), so if PHP doesn't suit you but VB does, you should try ASP(.NET).Any other server side scripting language might also do the trick though. Cold Fusion, JSP, etc. Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted May 2, 2006 Author Share Posted May 2, 2006 OkI was looking into in Visual Basic, because I wnat to stay away from servers right now, I just don't enough and don't have time to learn. I am already using xsl to display the info, I just need get the data from a text file. I don't think a script is right for this program, I need it simple as I found out yesterday. Link to comment Share on other sites More sharing options...
dooberry Posted May 2, 2006 Share Posted May 2, 2006 VBScript will support something called (eurrgh!!) the "Scripting.FilesystemObject".If you create a new instance in vbscript of the above object (provided you are running IE to do the work), you will be able to read from the file using delimiters (e.g. a space character) to separate data items.You can then use a second instance to output to a new file and add in your xml tags.The most horrible thing about this is that you have to know when the data items start and end and what each data element contains.try looking at this link and see if it helps:msdn FileSystemObject referenceIf there is any way at all that you can change the output of the data to have better delimiters and write one "record" per line of data then I would suggest you do it - this will save you a lot of heartache when you convert the data.Hope this helps, give me some feedback if it doesn't. .Dooberry Link to comment Share on other sites More sharing options...
StarGateSG-1 Posted May 2, 2006 Author Share Posted May 2, 2006 Good for me, since I know when the data items start, I also can generate data files whihc only data I will use. Link to comment Share on other sites More sharing options...
dooberry Posted May 3, 2006 Share Posted May 3, 2006 Yeah,I forgot to mention that you will need an instance of the TextStreamObject object as well, but the reference for this won't be far away from the link I gave you, sorry about that.In the words of Joey Tribiani's agent No harm, No Fooull!!Have fun.Dooberry. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now