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

Author Message

edwige fontenay

Tuesday 06 April 2010 8:48:21 am

Hello everybody,

I try to find a solution to offer to ezpublish 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

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

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

eZ debug

Timing: Jan 30 2025 19:32:02
Script start
Timing: Jan 30 2025 19:32:02
Module start 'layout'
Timing: Jan 30 2025 19:32:02
Module start 'content'
Timing: Jan 30 2025 19:32:03
Module end 'content'
Timing: Jan 30 2025 19:32:03
Script end

Main resources:

Total runtime1.3312 sec
Peak memory usage8,192.0000 KB
Database Queries64

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.3828151.2422
Module start 'layout' 0.00580.0058 739.6250220.7656
Module start 'content' 0.01171.3189 960.39064,533.8359
Module end 'content' 1.33050.0007 5,494.226612.0938
Script end 1.3312  5,506.3203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00660.4945160.0004
Check MTime0.00130.0999160.0001
Mysql Total
Database connection0.00110.082510.0011
Mysqli_queries1.234592.7343640.0193
Looping result0.00060.0429620.0000
Template Total1.264995.020.6324
Template load0.00480.363020.0024
Template processing1.260094.650720.6300
Template load and register function0.00140.108610.0014
states
state_id_array0.00220.166610.0022
state_identifier_array0.00190.141320.0009
Override
Cache load0.00450.3397280.0002
Sytem overhead
Fetch class attribute can translate value0.00210.161440.0005
Fetch class attribute name0.00200.148060.0003
XML
Image XML parsing0.00250.184940.0006
class_abstraction
Instantiating content class attribute0.00000.001060.0000
General
dbfile0.00340.2535220.0002
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs