...

View Full Version : Markup Validation W3C



oosh
01-22-2009, 03:21 AM
im trying validate this html which contains javascript, i cant seem to work out what to change to make it correctly validated, there are several different kind of parsing errors and another few things, the page loads and appears fine tho:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Oil Producing and Consuming Countries</title>
<link rel="stylesheet" href="oil_style.css"/>
<script type="text/javascript">
function readXML()
{var paraText ;
var newRow ;
var newPara ;
var newCell ;

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("oil_2.xml")

var country_producer = xmlDoc.getElementsByTagName("country_producer")
var theTable = document.getElementById("producertable")
var theTableBody = document.createElement("tbody")


for(var i=0; i<country_producer.length;i++)
{newRow = document.createElement("tr")
paraText= document.createTextNode(country_producer[i].getElementsByTagName("name")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
paraText= document.createTextNode(country_producer[i].getElementsByTagName("produces")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow)
paraText= document.createTextNode(country_producer[i].getElementsByTagName("supplies")[0].firstChild.nodeValue)
newPara = document.createElement("p")
newPara.appendChild(paraText)
newCell = document.createElement("td")
newCell.appendChild(newPara)
newRow.appendChild(newCell)
theTableBody.appendChild(newRow)

}
theTable.appendChild(theTableBody)
}
</script>

</head>

<body onload="readXML()">
<div class="page_header">
<h1>Top Ten Oil Producing Countries</h1>
</div>
<div>
<table class="oil_data_table" id="producertable" width="400px" border="2px">
<tr class="oil_data_table_headers">
<td>Producer</td>
<td>Amount</td>
<td>Supplier To:</td>
</tr>
</table>
</div>

<table class="next" width="700px" border="0px">
<tr>
<td></td>
<td></td>
<td><a href="javascript2.html">next</a></td>
</tr>
</table>

</body>
</html>

rangana
01-22-2009, 06:15 AM
You need to surround your script with CDATA islands when you are serving your page as XHTML.

Alternatively, making your script external will get you out of all your validation woes.

For further reading:
https://developer.mozilla.org/En/Properly_Using_CSS_and_JavaScript_in_XHTML_Documents
http://javascript.about.com/library/blxhtml.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum