Search best way to upload xml file and to use it in javascript code

Search best way to upload xml file and to use it in javascript code

Tuesday 06 April 2010 8:48:21 am - 3 replies

Author Message

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

edwige fontenay

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

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.