dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: Javascript/XML

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Minden, NV
    Posts
    7

    Red face Javascript/XML

    I am a new guy, and only learn to program as little as possible. I have been programming since the early 1970's and have written many programs in C. By the time I construct things in my head, it is like pulling fingernails to actually write the code. That said:

    I want to use javascript to create item links. I want to use the item numbers to get the information needed from an XML object. Here is an example of the XML object that I can query:

    http://www.wowhead.com/?item=48294&xml

    I need to get at least the item's name and quality id into my own variables (preferably javascript variables) that can be used to create links like the one below the "Under Construction" sign on this page:

    http://compuball.com/WoW/TheoryCraft...BiS/index.html

    That is a link to the item queried by the xml link above.

    How do I go about setting a variable to capture the XML values? Or, must I use Perl or some other CGI method for this page construction?

  2. #2
    Join Date
    Jan 2005
    Posts
    372
    The short answer is that you need to look into some AJAX - look for a tutorial or two and check whether they are using the same setup as you are - ie do they rely on Prototype, jQuery or similar.

  3. #3
    Join Date
    Oct 2009
    Location
    Minden, NV
    Posts
    7
    Thanks ... more goodies to learn. I will ask them and familiarize myself. If anyone else has any ideas ... I am open.

  4. #4
    Join Date
    Mar 2008
    Posts
    73
    You could use the XML Objects or the Node Object. Then access each node/element in the XML document. Just as you would and HTML document.

  5. #5
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    Neither javascript or AJAX can parse xml from a different domain for security reasons. You can import the xml to your domain and then parse it. This is easily done in php. You can either create a "proxy" (a nice example here) and parse it on the client side or you can retrieve the xml (and cache it if it is fairly static) and parse it on the server side. Lots of different php options for this route.

  6. #6
    Join Date
    Oct 2009
    Location
    Minden, NV
    Posts
    7

    Cool Ah ... <clink clink rattle>

    Quote Originally Posted by opifex View Post
    Neither javascript or AJAX can parse xml from a different domain for security reasons. You can import the xml to your domain and then parse it. This is easily done in php. You can either create a "proxy" (a nice example here) and parse it on the client side or you can retrieve the xml (and cache it if it is fairly static) and parse it on the server side. Lots of different php options for this route.
    Yep, my stupidity is terminal. I wrote an AJAX script to load the XML from the other server. I came here this time to ask why the ***.readyState would not increase beyond the value of 1, and there was your answer as the last post.

    Thanks opifex,
    I am off to the realm of PHP. I'll get back on when I reach a block on that one. It will probably take my old slow mind a a few days to learn enough that I realize there is something else, simple as can be, that I am lacking in knowledge. I have learned a lot from the study of AJAX and DOM. Maybe even enough to parse this thing once I get it onto my server

    EDIT:
    Looked at the proxy routine. Nice but I think it unnecessary until I break down and try to write a tunnel proxy for my travels.
    I can load the XML to my server, the content is fairly static, and can be reloaded when it happens to change (once every couple of months perhaps). Would opifex or someone else have a link to a PHP routine to cache XML from another server to my own?
    Last edited by Drae; 11-03-2009 at 06:04 PM.

  7. #7
    Join Date
    Oct 2009
    Location
    Minden, NV
    Posts
    7
    Do you have a reference to code that would save xml from one server onto my own? I noticed in the script you wrote for a proxy server, that you simply opened the remote server with the fopen and read it in 4096 chunks. Would I simply open it and the write it to a local file.

  8. #8
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    THIS is probably one of the cleanest examples around. I recently used this snippet as the base for weather feed reader. It shortened my old code by more than half.
    Will only run on PHP5.

  9. #9
    Join Date
    Oct 2009
    Location
    Minden, NV
    Posts
    7
    Thanks for all of your help. It is appreciated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles