Forums / General / Search best way to upload xml file and to use it in javascript code
edwige fontenay
Tuesday 06 April 2010 8:48:21 am
Hello everybody,
I try to find a solution to offer to Exponential content manager a way to upload a xml file in the admin access. Moreover, this xml file, must be get in a jquery code, to read his content. How can i made this, without link to a cached file in storage directory.
I appreciate some help.
I precised that, I'm newbie, in ez development.
Thank.
Edwige.
Patrick Kaiser
Wednesday 07 April 2010 2:53:26 am
Hi Edwidge,
just alter an existing content-class (or create a new one) and add a file attribute to it (name it for example xml_file).
Create a contentobject from this class and upload the xml-file to the xml_file attribute.
Than you can acess the full path to the xml-file in a template by first fetching the content object and than accessing the xml_file attribute via the objects data_map.
(In this example the content_object is assigned to node_id 100, the name of the file attribute is xml_file)
{def $myFileObject = fetch( 'content', 'node', hash( 'node_id', 100))} {def $myFileURL = $myFileObject.data_map.xml_file.content.filepath|ezroot} {* Now use it in your javascript *} <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> var xmlfile = '{$myFileURL}'; {literal} $(document).ready(function() { $.ajax({ type: "GET", url: xmlfile, dataType: "xml", success: doSomethingWithXML }); }); doSomethingWithXML = function( data ) { // your code to deal with the xml } {/literal}
Hope you got the idea.
Best regards, Patrick
Monday 12 April 2010 8:45:43 am
Thanks for your help.
It works fine. I just change
var xmlfile = '<span>{</span><span>$myFileURL</span><span>}</span>'; to var xmlfile = <span>{</span><span>$myFileURL</span><span>}</span>;
Nicolas Pastorino
Tuesday 13 April 2010 3:17:40 am
Hi Edwige,
Good to read you got a solution to your problem :)You may now want to mark the topic as solved (small ticker at the left of the topic's title above).
Cheers,
-- Nicolas Pastorino Director Community - eZ Member of the Community Project Board eZ Publish Community on twitter: http://twitter.com/ezcommunity t : http://twitter.com/jeanvoye G+ : http://plus.tl/jeanvoye