Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using DOM to grab images & flash from xml file?

    I have a xml file which contains all the text only.

    Currently, Im using DOM (javascript-- document.write(xmlDoc.getElementsByTagName("para").item(1).text) to grab the text from the xml file to display it using html.

    Ques.- Can i also use the DOM (javascript) to grab images & flash from the xml file? What should i type in the xml & javascript?

  • #2
    New Coder
    Join Date
    Oct 2002
    Location
    Atlanta
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, you can set it up to pull a filename from the XML data source and then create a <IMG> tag and insert that tag back into your document; I did something similar, but using straight XSLT. Obviously the images will have to already exist on the machine (server/client) that you want to pull, and you'd need to know the location of 'said' image/flash files.

    So if your XML would contain an element like

    <image>images/myimage1.gif</image>
    <image>images/myimage2.gif</image>

    Then in your Java, you would get those Nodes, and for each node, you would create an <IMG src='myImageVar'> (where 'myImageVar' is a variable that contains the value of each an element) tag and insert that tag, say, into a TABLE object or the like. When the page loads, your images should display.

    Now, if you're talking about encoding an actual image or flash file into an XML data file, I'm sure there's a way to do that, but since I've never tried, I can't provide that information.

    Hope this made sense, if not, let me know.

  • #3
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the code to insert a image in a javascript?

  • #4
    New Coder
    Join Date
    Oct 2002
    Location
    Atlanta
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok,

    Short of trying to explain all that, I am attaching a full blown example that you can see, use, mess with, modify, delete ... whatever.

    Contains:
    1 - XHTML Document
    1 - Very basic XML File
    1 - As basic as I can get it, Java Script
    4 - very small images (smilies)

    The idea is that we use the XML to name those images in the image folder, load the XML through script, build our HTML IMG tags in script, and then insert them back into the HTML through the DOM.

    *take a breath here*

    NOW - I have ONLY TESTED THIS IN Internet Explorer 6.0, so please don't tell me it's not working in Netscape. I leave that functionality up to you to figure out (if it's not working); didn't seem to work in Mozilla, so ...

    Questions? Comments? Fan mail?

    Attached Files Attached Files

  • #5
    Dan
    Dan is offline
    New Coder
    Join Date
    Oct 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im sorry dhtroy, but im using:

    document.write(xmlDoc.getElementsByTagName("para").item(0).text)

    IM attaching my file, please browse thro' . Thanks
    Attached Files Attached Files

  • #6
    New Coder
    Join Date
    Oct 2002
    Location
    Atlanta
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dan,

    I'm not certain what the real problem is that you're having, perhaps I'm not understanding the information provided, but regardless ... I replaced the function called insertImage() in the JavaScript with another function I hacked out called writeImage(). It does exactly the same thing, except for the the following line:

    Original script:
    divImages.innerHTML = strHTML;

    New script
    document.write( strHTML );

    They both work just fine, the second implementation obviously using the "document.write" method. You can make this change to the script I original posted to see the results for yourself. Using syntax similar to yours, it would look something like:
    document.write( "<img src='" + xmlDoc.getElementsByTagName("Image").item(1).text + "'></img>") I'm just building the string and placing it in a variable called strHTML before passing it to the write() method.

    If this still isn't "what your looking for", then I'm not certain I can help without more detailed information.

    Hope that helps.
    D.
    Last edited by dhtroy; 11-18-2002 at 06:37 PM.


  •  

    Posting Permissions

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