DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: getElementById workaround for Mozilla?

  1. #1
    Join Date
    Jul 2008
    Location
    RTP, NC
    Posts
    3

    getElementById workaround for Mozilla?

    My overall goal is to write a script which will draw from 5 different xmls, one at a time, and query/manipulate them to populate a side column. There will be a parameter passed from the individual html pages to the main script which will use an id element to select what nodes of the xml file to display. (In example below, "growth" is an id which will be used from xml to xml to xml to select those elements which belong to a certain program to display. Every item in an xml may be assigned to more than one program.) I've gotten step one, which is to import, query, and display, however, I can only display in IE...not in Mozilla nor Safari.

    My main current problem is that I need to be able to perform something like a getElementById on the xml, but that doesn't work in Mozilla or Safari. The construct:

    xmldoc.getElementsByTagName("item[@id=growth]")

    isn't supported by Mozilla...particularly the "@id=growth" part. I've only seen one potential work around for this, using "evaluate", and it doesn't work when I've tried it. Can anyone help me work this out? Thanks in advance.

    (I'm a complete beginner at xml and javascript, and, I'm trying to teach myself, so please bear with me. Php cannot be used because our web host doesn't support it and I'm helpless to switch host services.)

    THE XML:
    Code:
    <?xml version="1.0" encoding="utf-8"?> 
    <links> 
        <item id="growth"> 
            <program>Growth</program> 
            <category></category> 
            <title>THIS IS FILE 1</title> 
            <desc></desc> 
            <href></href>         
            <comment></comment> 
            <postdate></postdate> 
        </item> 
        <item id="bubba"> 
            <program>BUBBA</program> 
            <category></category> 
            <title>THIS IS FILE 2</title> 
            <desc></desc> 
            <href></href>         
            <comment></comment> 
            <postdate></postdate> 
        </item> 
    </links>
    THE SCRIPT:

    Code:
    <script> 
    function loadXML(url, handler) { 
         if (document.implementation && document.implementation.createDocument) { 
            var xmldoc = document.implementation.createDocument("", "", null); 
            xmldoc.onload = function(  ) { handler(xmldoc, url); } 
            xmldoc.load(url); 
        } 
        else if (window.ActiveXObject) { 
            var xmldoc = new ActiveXObject("Microsoft.XMLDOM");    
            xmldoc.onreadystatechange = function(  ) {               
                if (xmldoc.readyState == 4) handler(xmldoc, url); 
            } 
            xmldoc.load(url);                                     
        } 
    } 
    
    function makeTable(xmldoc, url) { 
        var place = document.getElementById('res'); 
         
        var table = document.createElement("table"); 
        table.setAttribute("border", "1"); 
        table.setAttribute("id", "links"); 
        place.appendChild(table); 
    
        var items = xmldoc.getElementsByTagName("item[@id=growth]"); 
    
        for(var i = 0; i < items.length; i++) { 
            var lnks = items[i]; 
            var title = lnks.getElementsByTagName("title")[0].firstChild.nodeValue; 
    
            var row = document.getElementById('links').insertRow(0); 
            row.style.backgroundColor = i%2?'#fff':'#e5dbca'; 
            row.insertCell(0).appendChild(document.createTextNode(title)); 
        } 
    } 
    </script>

  2. #2
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    Trye this

Similar Threads

  1. Can't pass Variable to getElementByID
    By rayfinkel2 in forum AJAX
    Replies: 2
    Last Post: 08-17-2008, 11:07 PM
  2. Can't pass Variable to getElementByID
    By rayfinkel2 in forum Web
    Replies: 1
    Last Post: 02-15-2007, 08:51 PM
  3. getElementById to find textbox value
    By bdc604 in forum ASP.NET
    Replies: 0
    Last Post: 07-10-2006, 03:15 AM
  4. Replies: 2
    Last Post: 08-15-2001, 03:02 AM
  5. Replies: 0
    Last Post: 01-10-2001, 10:49 AM

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center