[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XHTML Strict / XML Validation error (using Javascript)

Posted on 2009-04-23
3
Medium Priority
?
1,205 Views
Last Modified: 2013-11-19
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
Comment
Question by:2bears
3 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 750 total points
ID: 24225444
 xmlDoc.load("Recipe1.xml");

this line loads a xml file, it does not read <body> content !!!
0
 
LVL 1

Assisted Solution

by:lesavare
lesavare earned 750 total points
ID: 24229733
"<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
 

Author Closing Comment

by:2bears
ID: 31574115
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question