View Full Version : XML download file formats?
Fou-Lu
03-05-2005, 11:37 AM
Not sure if anything like this has been touched or not.
I'm *fairly* new with XML and was considering constructing my resume in XML so that I could easily create an html, MS Word, and plain text files, as well as for easy printability. I figure this can all be done using a mix of php, xml, xsl and css. Now, my bigger question for it all, is can XSL alter the xml to format it as plain text file? I'd be happy if this can put the information in, with the correct line breaks where I format them, into a textarea, or as a download .txt file. Can this be done? If so, can you give me an idea as to how to create the download?
Alex Vincent
03-05-2005, 08:43 PM
I'm 99% sure it can be done, but I have no idea how.
brothercake
03-05-2005, 08:45 PM
What is it you're after - an XSL stylesheet to convert your XML into plain text, or the server-side mechanism to create and offer the resulting file for download? or both?
Fou-Lu
03-06-2005, 08:29 PM
I'm not really looking for how it can be done, more of the best way of doing it. I mean, can I create an xsl to change it to plain text? Cause that would be awesome, I can just use php or whatever to create a downloadable file from there. I had jumped to the conclusion that this could be done with xml, but as I mentioned I have just started to realize the potential xml has and have therefore just recently begun using it.
I guess this thread should really be more of a what is the best method post. Should I process it on server side using either a server side XSL processor, or an DOMXML, or can I just do this using a client side sheet?
I'll fiddle around with it a bit, see how it comes out. If you have any suggestions though, or have a recommended route that I should use, that would be great, I'd appreciate any input you could spare!
codegoboom
03-07-2005, 05:54 AM
I'd approach the problem by figuring out how many ways it's possible, and then choose the best one, based on specific criteria... ;)
brothercake
03-07-2005, 05:04 PM
I mean, can I create an xsl to change it to plain text? Cause that would be awesome, I can just use php or whatever to create a downloadable file from there.
Yes, no problem - XSL can create any kind of data. But iirc PHP (even 5) doesn't come with an XSLT processor .. you may need to install one - such as Sablotron -- http://www.gingerall.com/charlie/ga/xml/p_sab.xml
or an DOMXML, or can I just do this using a client side sheet?
Well there are DOM XML (http://www.php.net/manual/en/ref.domxml.php) extensions for PHP4 (also not pre-installed) and in PHP5 there are DOM extensions (http://www.php.net/manual/en/ref.dom.php) already installed - but they're pretty inefficient, because they hold the entire document in memory at once.
So the third alternative, which is possibly your best bet, is to use the expat parser -- http://www.php.net/manual/en/ref.xml.php It's a linear parser (not DOM - just "open tag", "close tag" and "cdata" handlers, run in that order) but there's plenty of docs about it - doesn't take long to get used to.
I wouldn't bother trying to do it client-side - you'll lose too many browsers, and in any case, all you'd be able to do is display it, not create a file and offer it for download.
Fou-Lu
03-08-2005, 03:56 AM
Excellent, thanx for your suggestions guys!
I've already installed the sablotron when I first set up my php (at the time I wouldn't have known what it was for, but was included with the package I d/l'd from a site), which works out well.
Good point as well, ATM this is only for my own use, but I suppose that in the future I may create a simple homepage for myself and include this on it. If the users cannot view it correctly, then it would be pretty much useless yeah? Lol.
Quick question though, as it is I'm having a little trouble creating new lines. I don't really have sufficient code for you to look at, but when I create a text output with a text/plain type, then new lines appear as it would be. In php I often use the \n to create new lines, but obviously this is not being parsed and is taken as input. How would I go abouts creating \n to create a new line? Is there already a method? Or alter a DTD for it? Or I guess I should ask, I haven't done anything with the server side processer yet, so could that be my problem, the browser?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.