[solved] xml request local .xml file

here you will find only solved Help topics

Moderator: 1.2 Moderators

[solved] xml request local .xml file

Postby runwildwood on Sat Jul 24, 2010 1:49 am

mt version 1.2.4
i've read the documentation and searched the forums. being new though i'm tripping up on a simple problem of loading in a local xml file.

//here is my xml:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <app>
  3.     <item>
  4.         <title><![CDATA[cash]]></title>
  5.     </item>
  6.     <item>
  7.         <title><![CDATA[money]]></title>
  8.     </item>
  9.     <item>
  10.         <title><![CDATA[bacon]]></title>
  11.     </item>
  12. </app>


//here is my loadXML function:
  1. var loadXML = function() {
  2.  
  3.     var myRequest = new Request({
  4.         method: 'get',
  5.         url: 'data.xml',
  6.         onComplete: function(response) {
  7.                         alert('gets this far');
  8.             response.getElements('item').each(function(item) {
  9.                 alert(item.getElement('title').get('text'));
  10.             });
  11.         }
  12.     })
  13.    
  14.     myRequest.send();
  15. }


the onComplete will fire but not the response getElements function. ideally i want to load up the xml into arrays, but first i just need to confirm that the data is available.
thanks,
josh
Last edited by runwildwood on Wed Jul 28, 2010 8:34 pm, edited 1 time in total.
runwildwood
 
Posts: 6
Joined: Sat Jul 24, 2010 1:35 am

Re: xml request local .xml file

Postby fyrye on Sun Jul 25, 2010 2:37 am

do this
  1. new Request({
  2.    method: 'get',
  3.    url: 'data.xml',
  4.    onComplete: function(){
  5.       alert('Finished Getting the document');
  6.    },
  7.    onSuccess: function(response){
  8.        alert('The response is: ' + response);
  9.    },
  10.    onFailure: function(){
  11.       alert('Something Went Wrong');
  12.    }
  13. }).send();


See what your results are...


If you are trying to load an XML file from your local harddrive from an external website or from a browser, it is NOT possible without using an application.
This is due to security issues of the same. Look into JAVA (not script), Flash, Air 2, Google Gears, or ActiveX.
http://www.adobe.com/products/air/ (watch the video for details)
http://www.adobe.com/products/air/develop/ajax/ for the API keep in mind ECMAScript = Javascript/ActionScript
In all due respects it used to be possible in windows 98 using FSO and other hacks, which have long since been fixed.
Client-side JavaScript Run-Time is now separated into 2 categories, Internet/Web Based and Local/Client Based (JScript).
EG:
  1. var fso = new ActiveXObject("Scripting.FileSystemObject");

Will not work in any other browser than IE, and current versions of IE will not create the object, while it runs fine if executed on a local system from a .js file eg: the wshell run-time environment, not the browser's.
User avatar
fyrye
mootools enthusiast
 
Posts: 162
Joined: Sat Dec 20, 2008 10:16 am

Re: xml request local .xml file

Postby runwildwood on Tue Jul 27, 2010 12:27 am

thanks for the info. i come from the flash/as3 side of the world so was expecting something more straightforward. a coworker mentioned spry as a way to simplify loading in xml as well:
http://labs.adobe.com/technologies/spry/
runwildwood
 
Posts: 6
Joined: Sat Jul 24, 2010 1:35 am

Re: xml request local .xml file

Postby fyrye on Tue Jul 27, 2010 1:57 am

Spry is similar to MooTools, WEB 2.0 aka: AJAX Framework.
The J in AJAX is JavaScript

Web + Local != easy.
If I read the OP correct you are wanting to request the XML file from a local system to upload to the site the local system is viewing without user interaction.
EG:
Me->YourSite->Requests File->Me->YourSite->Process File->Show Results->Me
Instead of
Me->YourSite->Me->Clicks Upload File->YourSite->Process File->Show Results->Me

Every security measure possible is taken to prevent the first simply because of the amount of malicious developers out there looking to compromise your system.
Thus requiring the user to agree to and install an application to make things work (this used to be capable with out confirmation *shock*)
Imagine you have your resume, address book, emails, ip address, etc stored on your PC.
By allowing JavaScript access via a browser, if you were to go to a website that had malicious code or an advertisement that contained malicious code, what someone could do with the found information? Malicious advertisers already make a fortune on stealing video game accounts by exploiting flash on the targeted video game's help websites. As well as even stealing credit card information from other websites just by recording keystrokes.
This is where Flash, comes in and why it's currently one of the major exploited programs by malicious developers. EG: a malicious programmer can have a flash advertisement record keystrokes, retrieve system information, cookie/session states, copy clipboard contents, and in some cases even execute remote files granting someone access to the affected PC.
http://www.symantec.com/connect/blogs/next-generation-flash-vulnerability
http://www.symantec.com/connect/blogs/analysis-zero-day-exploit-adobe-flash-and-reader

The list goes on..

Another type of exploit is XSS where a malicious user injects malicious code into your website giving them details about your users, access rights, cookie theft etc. That is one reason why AJAX isn't designed to request data from 1 domain to another.

Your best bet for retrieving Local data to serve to the web without explicitly clicking browse -> select XML file is JAVA(not script) IMHO.
If clicking browse or the file is already uploaded to the server then an AJAX request should be fine.
User avatar
fyrye
mootools enthusiast
 
Posts: 162
Joined: Sat Dec 20, 2008 10:16 am

Re: xml request local .xml file

Postby runwildwood on Tue Jul 27, 2010 9:18 am

I'm just loading the XML locally while in development. The end result will request the XML on the server. (in case that was causing any confusion)

Big picture we have a flash site that is driven by an XML file. It's our goal to have the HTML version run off that same XML file so that when the cms publishes the new data the changes are reflected in both sites.
runwildwood
 
Posts: 6
Joined: Sat Jul 24, 2010 1:35 am

Re: xml request local .xml file

Postby fyrye on Tue Jul 27, 2010 9:25 pm

Ok then, you should be able to build a class (object) that performs the functions you need to provide you with that functionality, then use Request to process the information.
http://torntech.com/Examples/xmlRequest/

If you are running locally, what is your structure setup like?
Windows / *nix / IIS / Apache / PHP/ASP.net / CFM etc?

If you have the means, setup your Local PC as a webserver (IIS/Apache/NginX) which will allow you to do http://localhost and access the data as if you were on the internet.
Which will give you testing grounds for determining the final outcome, and not as steep of a change when migrating your sandbox to the production.

I apologize for the confusion usually when someone refers to local (file), they are referring to pulling the data from a client visiting their website.
User avatar
fyrye
mootools enthusiast
 
Posts: 162
Joined: Sat Dec 20, 2008 10:16 am

[solved] xml request local .xml file

Postby runwildwood on Wed Jul 28, 2010 8:33 pm

now i'm working within my localhost directory in osx and it works great. thanks for your help.
runwildwood
 
Posts: 6
Joined: Sat Jul 24, 2010 1:35 am


Return to Solutions

Who is online

Users browsing this forum: No registered users and 2 guests