how to access xml from server?

0 favourites
  • 6 posts
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • To access php files with ajax object stored in a server you need to add a "header access-control..." to the file.

    But what about xml files, how do I access it?

    Tryed but couldn't get the information of the file with AJAX and from what I know xml are just files that you storage information, so how do I request it from a webserver if there's no header in xml?

  • Do you mean the 'Access-Control-Allow-Origin' HTTP header? That is only necessary if you are requesting a file from a different domain (e.g. requesting example.com/test.xml from scirra.com/demo.html). If you are making a cross-domain request, you need to set the server up to respond with that HTTP header - the file contents are not affected.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley I managed to request a picasa feed just with AJAX.

    The astuce was to use yql (yahoo query language)

    It seems query.yahooapis.com allows cross domain requests

    you use it by requesting an url like that:

    http://query.yahooapis.com/v1/public/yql?q=select * from xml where url="https://picasaweb.google.com/data/feed/base/user/112730361158490336509?alt=rss&kind=album&hl=en_US&imgmax=1600"

    looks like an SQL query (:

    I managed to make this prototype

    https://dl.dropbox.com/u/23551572/C2-Games/Picasa/index.html

    Depending on my motivation I might make an entire picasa viewer.

    The only issue I had it that the xml object really don't like namespaces. It makes the XPath query fail.

    I had to cleanup the xml and remove all the namespaced markup and attribute before loading it in the XML object.

    I think I read that IE xml parser doesn't know how to deal with namespace, that might be why it's not yet implemented in C2 (?) but it would be great if at least there was a temporary action that would cleanup the namespace on load.

    Anyway I managed to make it work (:

  • Do you mean the 'Access-Control-Allow-Origin' HTTP header? That is only necessary if you are requesting a file from a different domain (e.g. requesting example.com/test.xml from scirra.com/demo.html). If you are making a cross-domain request, you need to set the server up to respond with that HTTP header - the file contents are not affected.

    Hi Ashley thanks for reply

    I have a webserver running on my pc and there's a file located like: localhost/test.xml

    My game is running outside the 'https' directory from the webserver, in a normal folder on my PC and in preview, I used AJAX to request this test file but it can't access it, does nothing.

    For php files I used whoever the header 'access-control' like you said and it works if I request with AJAX.

    so my problem are with .XML files..

  • Sorry for bumping the post again, but I really need to understand well what's possible and not possible.

    Also if there's another one with the same questions they might have some answers here..

    I will explain with details what I'm trying and how I'm doing..

    there is a webserver running in my PC, php files are inside the 'htdocs', however the game isn't in 'htdocs', it's in a local folder.

    I can request php files with AJAX running in preview mode (adding the header to allow access), but I can't request .XML files. When I request a .xml file and add below a condition AJAX->On "xml request" Completed and add some simple actions to check if it has succeed to get it, nothing happens, meaning that AJAX failed to retrieve the file from the webserver, probably because of security definitions..

    Now.. comes the question, so how do I successfully request a .xml file from a webserver?

    I'm trying some solutions.. one of them is request a .php file with '(header('Access-Control-allow..')' and add "simplexml_load_file" to load the .xml file, then use the function 'asXML()' to send the whole xml information to AJAX.

    example:

    <?php
    header('Access-Control-Allow-Origin: *');
    
    $xml = simplexml_load_file("test.xml");
    echo $xml->asXML();
    ?>
    

    After requested, load the ajax.lastdata to XML Object

    this formula currently is working, but isn't the most efficient way...

    Concluding, after all, is it possible to request("REQUEST URL") .XML files from a webserver using AJAX object? I already tried but couldn't succeed to request it, so if anyone know how to do it, please make a tutorial explaining..

    Thanks

  • Hi Ashley I'd like to see a working example of this as well. I'm wasting too much time trying to get my project to work and all I want is to access an xml in my download folder in my online server from my C2 runtime test to adjust a game I'm working on. I don't want to include the xml files on the game otherwise I'd have to update the game for every little change on the xml.

    EDIT: I solved my issue for testing purposes with a .htaccess file with the line Header set Access-Control-Allow-Origin "*"

    placed in the folder with the file I want to access.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)