XHTML Strict / XML Validation error (using Javascript)

Posted on 2009-04-23
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
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"



<html xmlns = "">



   <title>Parsing Recipe1.xml file using Javascript</title>


   <style type = "text/css">

		html {

		background-color: #FFFF66;	


		body {



		font-family:"Comic Sans MS", Arial, sans-serif;



		h1 {




		p, ul {




		li {



		list-style-type: none;


		.nav {

		font-family:"Times New Roman", Times, serif;



		.emp {



		.heading {






<!-- 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.



					else {

					alert('Your browser cannot handle this script');



					if (xmlDoc!=null){ 





   // 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\>" 


						outputHTML += ind.childNodes[c].attributes.getNamedItem('quantity').nodeValue+ '&nbsp;';



						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\>"









<body onload="parseXML();">

<xml id="xmlRecipe" src="Recipe1.xml"></xml>

   <div id="outputDiv">



    <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> 




Open in new window

Question by:2bears
    LVL 18

    Accepted Solution


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

    Assisted Solution

    "<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.

    Author Closing Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to count occurrences of each item in an array.
    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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now