Current location: Hot Scripts Forums » General Web Coding » JavaScript » Xml / Dom / Css

Xml / Dom / Css

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-29-05, 09:05 AM
Mark_SC.SE Mark_SC.SE is offline
New Member
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Xml / Dom / Css

I have an ASP page (No need for it to be ASP, just a force of habit )

The structure of this page is as follows:
  1. Click on the link at the top of the page
  2. The link then uses the DOM to create a set of DIV's (Looks like a navigational bar)
  3. The DIV's pull in XML data

The Problem:

The problem lies (Where else) with Internet Explorer. It works fine in Mozilla. Test it in Firefox (1.0.4) and you'll see what the result is supposed to look like.

If you look at it in Internet Explorer, it creates the DIV's and pulls in the XML contents, but the styles that I've applied to the DIV's via the DOM do not work? It displays in I.E simply as black text on white background?

BUT! If I open up the generated html code from Firefox's "View Selection Source" and paste it back into the page then preview in I.E - The styles applied to the DIV's work!?

It's only when the DOM creates the DIV elements that the Styles aren't applied properly?

If anyone can offer any solutions to this I would be grateful.

Also an explanation as to why it doesnt work AT ALL! in Opera (8.0)?

Many thanks

Mark (See below for all code)

Entire page code:

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
Response.Buffer = true
Response.Expires = -1500
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>XML Menu [Internet Explorer/Mozilla/Gecko]</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT language="JavaScript" type="text/javascript">
<!--

function fnImportXML() {

  // Import for Mozilla (Using Object detection)
  if (document.implementation && document.implementation.createDocument){
	  
  	xmlDoc = document.implementation.createDocument("", "", null);
  	xmlDoc.onload = fnCreateMenu;
  	// NOTE: No brackets?
  	
  }
  
  // Import for Internet Explorer (Using Object detection)
  else if (window.ActiveXObject){
	  
  	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  		
  	// The 'readyState' has a value between 1 and 4.
  	// 4 means that all data has been received (= onLoad).
  	// So if it's 4, start creating the table.
  	xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) fnCreateMenu()};
  	
  } else {
	  
  	alert('Your browser can\'t handle this script');
  	return;
  	
  }
  
  // Load the XML data into the Object 'xmlDoc'
  xmlDoc.load("Menu.xml");
	
}

function fnCreateMenu() {

	var objXMLMenu = xmlDoc.getElementsByTagName('MENU');
	
	var iMenuCounter = 0;	
	var iCounter;
	var iSubElCounter = 0;
	var iSubEl = 0;
	
	for (iCounter=0; iCounter<objXMLMenu.length; iCounter++) {
		
		/*
		
		The variable "iSubmenuElements":
			Outputs the number of submenu elements per 'top level' elements:
			
		Add on note:
			The "iSubmenuElements" variable produces different output for both Mozilla and Internet Explorer?
			So we must change the calculation for the variable depending on the browser used. 
		
		*/
		
		if(navigator.appName == "Netscape"){
			var iSubmenuElements = (objXMLMenu.item(iCounter).childNodes.length - 1) / 2;
		}
		
		if(navigator.appName == "Microsoft Internet Explorer"){
			var iSubmenuElements = objXMLMenu.item(iCounter).childNodes.length;
		}
		
		// Create the 2 different elements ("Top Level Menu" / "Sub Menu")
		
		var objCreateRoot = document.createElement('DIV');
		objCreateRoot.setAttribute('id','Menu'+iCounter);
		objCreateRoot.setAttribute('style','width:130px; background-color: yellow; padding:5px 5px 0px 5px;');
		    
		var objCreateSub = document.createElement('DIV');    
		objCreateSub.setAttribute('id','SubMenu'+iCounter);
		objCreateSub.setAttribute('style','width:120px; background-color: #CCCCCC; padding:5px;');
		
		// Create the Paragraph elements for each parent 'menu' element.
		
		strAttribute = objXMLMenu[iMenuCounter].getAttribute("id");
		
		var objPara1 = document.createElement('P');
		var objText1 = document.createTextNode(strAttribute);
		
		objPara1.appendChild(objText1);
		objCreateSub.appendChild(objPara1);
		
		var strSubMenuElements = xmlDoc.getElementsByTagName("SUB");
		
		calNum = (objXMLMenu.item(iMenuCounter).childNodes.length - 1) / 2;
		
		iRoundElement = Math.ceil(calNum);
		
		// Write Sub Menu (Loop to write each 'top level' elements submenus elements)
		
		while (iSubElCounter < iSubmenuElements) {
			
			eval("objSubPara" + iSubEl + "= document.createElement('P')");
	  		eval("objSubText" + iSubEl + "= document.createTextNode(strSubMenuElements[iSubEl].firstChild.nodeValue)");
	  		eval("objSubPara" + iSubEl + ".appendChild(eval('objSubText' + iSubEl))");
	  		objCreateSub.appendChild(eval("objSubPara" + iSubEl));
	  		
	  		iSubElCounter = iSubElCounter + 1;
			iSubEl = iSubEl + 1;
			
  		}
		
		iSubElCounter = 0;
		
		objCreateRoot.appendChild(objCreateSub);
		
		document.getElementById('WriteDIV').appendChild(objCreateRoot);
		
		// Increments the counter so it loops through each top level menu
		iMenuCounter = iMenuCounter + 1;
		
	}
	
}

// -->
</SCRIPT>
<STYLE type="text/css">
<!--
BODY, P, TD {

	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
	font-style: normal;
	color: #000000;
	text-decoration: none;

}
-->
</STYLE>
</HEAD>

<BODY>

	<A href="javascript:fnImportXML();">Click here to create XML driven DIV menu (Internet Explorer/Mozilla/Gecko)</A>
	
	<P id="WriteDIV"></P>
	
</BODY>
</HTML>
Entire XML code:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>

	<MENU id="TopMenu1">
		<SUB>Menu 1 :: Sub Link 1</SUB>
		<SUB>Menu 1 :: Sub Link 2</SUB>
		<SUB>Menu 1 :: Sub Link 3</SUB>
		<SUB>Menu 1 :: Sub Link 4</SUB>
		<SUB>Menu 1 :: Sub Link 5</SUB>
		<SUB>Menu 1 :: Sub Link 6</SUB>
		<SUB>Menu 1 :: Sub Link 7</SUB>
		<SUB>Menu 1 :: Sub Link 8</SUB>
	</MENU>
	
	<MENU id="TopMenu2">
		<SUB>Menu 2 :: Sub Link 1</SUB>
		<SUB>Menu 2 :: Sub Link 2</SUB>
		<SUB>Menu 2 :: Sub Link 3</SUB>
		<SUB>Menu 2 :: Sub Link 4</SUB>
		<SUB>Menu 2 :: Sub Link 5</SUB>
		<SUB>Menu 2 :: Sub Link 6</SUB>
		<SUB>Menu 2 :: Sub Link 7</SUB>
	</MENU>
	
	<MENU id="TopMenu3">
		<SUB>Menu 3 :: Sub Link 1</SUB>
		<SUB>Menu 3 :: Sub Link 2</SUB>
		<SUB>Menu 3 :: Sub Link 3</SUB>
		<SUB>Menu 3 :: Sub Link 4</SUB>
		<SUB>Menu 3 :: Sub Link 5</SUB>
		<SUB>Menu 3 :: Sub Link 6</SUB>
	</MENU>
	
	<MENU id="TopMenu4">
		<SUB>Menu 4 :: Sub Link 1</SUB>
		<SUB>Menu 4 :: Sub Link 2</SUB>
		<SUB>Menu 4 :: Sub Link 3</SUB>
		<SUB>Menu 4 :: Sub Link 4</SUB>
		<SUB>Menu 4 :: Sub Link 5</SUB>
	</MENU>
	
	<MENU id="TopMenu5">
		<SUB>Menu 5 :: Sub Link 1</SUB>
		<SUB>Menu 5 :: Sub Link 2</SUB>
		<SUB>Menu 5 :: Sub Link 3</SUB>
		<SUB>Menu 5 :: Sub Link 4</SUB>
	</MENU>
	
	<MENU id="TopMenu6">
		<SUB>Menu 6 :: Sub Link 1</SUB>
		<SUB>Menu 6 :: Sub Link 2</SUB>
		<SUB>Menu 6 :: Sub Link 3</SUB>
	</MENU>
	
	<MENU id="TopMenu7">
		<SUB>Menu 7 :: Sub Link 1</SUB>
		<SUB>Menu 7 :: Sub Link 2</SUB>
	</MENU>

	<MENU id="TopMenu8">
		<SUB>Menu 8 :: Sub Link 1</SUB>
		<SUB>Menu 8 :: Sub Link 2</SUB>
		<SUB>Menu 8 :: Sub Link 3</SUB>
		<SUB>Menu 8 :: Sub Link 4</SUB>
	</MENU>

	<MENU id="TopMenu9">
		<SUB>Menu 9 :: Sub Link 1</SUB>
		<SUB>Menu 9 :: Sub Link 2</SUB>
		<SUB>Menu 9 :: Sub Link 3</SUB>
		<SUB>Menu 9 :: Sub Link 4</SUB>
		<SUB>Menu 9 :: Sub Link 5</SUB>
		<SUB>Menu 9 :: Sub Link 6</SUB>
		<SUB>Menu 9 :: Sub Link 7</SUB>
		<SUB>Menu 9 :: Sub Link 8</SUB>
		<SUB>Menu 9 :: Sub Link 9</SUB>
	</MENU>
	
</ROOT>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
xml problem plz help me EvilDeveloper PHP 0 05-11-05 12:53 AM
Need XML to PHP Parsing Done angmi90 Job Offers & Assistance 1 04-28-05 02:42 PM
importing xml to phpnuke block larryflynt PHP 0 10-22-04 04:59 PM
Scrollbar!!!!!! LiLSweetie HTML/XHTML/XML 8 07-22-04 06:01 PM
javascripting and XML Christoff JavaScript 1 06-23-04 06:44 AM


All times are GMT -5. The time now is 11:36 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.