Link to home
Start Free TrialLog in
Avatar of 2bears
2bearsFlag for New Zealand

asked on

XHTML Strict / XML Validation error (using Javascript)

Hi Experts
I have a validation error to be rid of, so the page validates "xhtml1-strict"
It is located just after the <body onload....> line at the bottom of the attached code.
.....................
Error message received:
"The tag name: "xml" Not found in currently active versions.
In the body section is <xml id="xmlRecipe" src="Recipe1.xml"></xml> "
1. The element "XML" is undefined.
2. The Attribute "src" exists, but can not be used for this element.
3. The  Attribute "id" exists, but can not be used for this element.
....................................
Kind regards
2bears
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns = "http://www.w3.org/1999/xhtml">
 
<head>
   <title>Parsing Recipe1.xml file using Javascript</title>
 
   <style type = "text/css">
		html {
		background-color: #FFFF66;	
		}
		body {
		padding:15px;
		background-color:#FFFF66;
		font-family:"Comic Sans MS", Arial, sans-serif;
		font-size:16px;
		}
		h1 {
		color:#339933;
		font-size:3em;
		}
		p, ul {
		color:#000000;
		font-size:.75em;
		}
		li {
		color:#000000;
		font-size:1em;
		list-style-type: none;
		}
		.nav {
		font-family:"Times New Roman", Times, serif;
		font-size:.75em;
		}
		.emp {
		font-style:italic;
		}
		.heading {
		text-decoration:underline;
		padding-bottom:3px;
		}
   </style>
   
<!-- Locating nodes in Recipe1.xml -->
   <script type = "text/javascript">
   <!--
   	var outputHTML = ""; // stores text to output in outputDiv
	var xmlDoc=null;
	
	if (window.ActiveXObject){
		// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
			else if (document.implementation.createDocument){
				// code for Mozilla, Firefox, Opera, etc.
				xmlDoc=document.implementation.createDocument("","",null);
	}
					else {
					alert('Your browser cannot handle this script');
	}
 
					if (xmlDoc!=null){ 
					xmlDoc.async=false;
					xmlDoc.load("Recipe1.xml");
	}
 
   // display the XML document 
   function displayDoc(){
   
      document.getElementById( "outputDiv" ).innerHTML = outputHTML;
	} // end function displayDoc
 
   // obtain and apply XML file
   function parseXML(){
   
		var rt = xmlRecipe.documentElement;
		outputHTML = "";
		if(rt.hasChildNodes) {
			outputHTML = "\<h1\>" + rt.selectSingleNode('title').text + "\<\/h1\>"
			outputHTML += "\<p\>" + rt.selectSingleNode('number_of_servings').text + "\<\/p\>"
			outputHTML += "\<p class='emp'\>" + rt.selectSingleNode('comment').text + "\<\/p\>"
			var ind = rt.selectSingleNode('ingredients')
			if(ind.hasChildNodes) {
				outputHTML += "\<ul\>" 
				outputHTML += "\<li class='heading'\>" +ind.attributes.getNamedItem('heading').nodeValue + "\<\/li\>"
				for(var c = 0;c < ind.childNodes.length;c++) {
					outputHTML += "\<li\>" 
					if(ind.childNodes[c].attributes.getNamedItem('quantity')){
						outputHTML += ind.childNodes[c].attributes.getNamedItem('quantity').nodeValue+ '&nbsp;';
	}
					if(ind.childNodes[c].attributes.getNamedItem('measure')){
						outputHTML += ind.childNodes[c].attributes.getNamedItem('measure').nodeValue + '&nbsp;';
	}
					outputHTML += ind.childNodes[c].text + "\<\/li\>"
	}
					outputHTML += "\<\/ul\>"
	}
			var prep = rt.selectNodes('preparation_instructions')
			if(prep.length>0) {
				for(var p = 0;p < prep.length;p++) {
					outputHTML += "\<p\>" + prep[p].text + "\<\/p\>"
	}
	}
			outputHTML += "\<p\>" + rt.selectSingleNode('cooking_instructions').text + "\<\/p\>"
	}
		displayDoc();
	}
 
-->
   </script>
</head>
 
<body onload="parseXML();">
<xml id="xmlRecipe" src="Recipe1.xml"></xml>
   <div id="outputDiv">
	
	</div>
    <div class="nav">
    <br />
    <a href="Recipe2.html">Recipe 2, HTML version</a>
    <br /> 
    <a href="Recipe1.xml">Recipe 1, XML version</a>
    <br />
    <a href="Recipe2.xml">Recipe 2, XML version</a> 
    </div>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pawel Witkowski
Pawel Witkowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 2bears

ASKER

Hi wilg32 and lesavare
Thank you for your response and explanation regarding function loading. When I lookrd at the code I noticed that my mistake was that the first variable was "xmlDoc" and not the "xmlRecipe" variable used elsewhere. When I changed it to "xmlRecipe"  and removed the "" line in the  the file validated Strict and worked fine.
Appreciate that help with this.
I awarded 250 each as the info from both posts pointed me towards the problem resolution.
Kind regards 2bears