• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1213
  • Last Modified:

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

0
2bears
Asked:
2bears
2 Solutions
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
 xmlDoc.load("Recipe1.xml");

this line loads a xml file, it does not read <body> content !!!
0
 
lesavareCommented:
"<xml id="xmlRecipe" src="Recipe1.xml"></xml>" is an example of a "XML data island". You are getting this error because the <xml> element isn't actually proper XHTML - it was created by Microsoft and can only be used in Internet Explorer.
It is usually regarded as a "don't" in terms of good practice, as it does not work in Firefox, Opera etc. and (as you have found) it is not W3C-compliant. If you use this element you will not be able to have validated XHTML. You should just stick with JavaScript.

http://www.w3schools.com/Xml/xml_dont.asp
0
 
2bearsAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now