Jump to content

XML parsing error.


tjmbc

Recommended Posts

This is a portion of my code that I am having problems with with the xml page pasted below. The script runs fine when I don't include the height and I can replace height with "width" and it will work. I just can't figure out why the code doesn't work when I try to parse the height. I pasted my full code at the bottom of this post.

 

function getXMLSuccess(originalRequest)

{

 

var resultText = "";

var response = originalRequest.responseXML;

 

var heights = response.getElementsByTagName('height');

var widths = response.getElementsByTagName('width');

var bgColors = response.getElementsByTagName('bgcolor');

var borders = response.getElementsByTagName('border');

 

var height = heights[0].firstChild.nodeValue;

var width = widths[0].firstChild.nodeValue;

var backColor = bgColors[0].firstChild.nodeValue;

var border = borders[0].firstChild.nodeValue;

resultText = height + " " + width + " " + backColor + " " + border;

 

 

createBox(height, width, backColor, border);

$('xmlResult').innerHTML = resultText;

 

}

 

 

 

 

 

 

 

 

//The xml page that is parsed.

  <mybox>

      <label>

        <height>100px</height>

        <width>300px</width>

        <bgcolor>#ff0000</bgcolor>

        <border>1px solid black</border>

      </label>

  </mybox>

 

 

 

 

 

 

 

<html>

 

<head>

<title>AJAX Midterm</title>

<script src="prototype-1.6.0.2.js" type="text/javascript"></script>

 

<script language="JavaScript" type="text/javascript">

 

var boxdiv;

 

function parseXML()

{

alert("parseXML Called");

}

 

function getXML()

{

new Ajax.Request('description.xml', {

method:'get',

onSuccess: getXMLSuccess,

});

}

 

function getXMLSuccess(originalRequest)

{

 

var resultText = "";

var response = originalRequest.responseXML;

 

var heights = response.getElementsByTagName('height');

var widths = response.getElementsByTagName('width');

var bgColors = response.getElementsByTagName('bgcolor');

var borders = response.getElementsByTagName('border');

 

var height = heights[0].firstChild.nodeValue;

var width = widths[0].firstChild.nodeValue;

var backColor = bgColors[0].firstChild.nodeValue;

var border = borders[0].firstChild.nodeValue;

resultText = height + " " + width + " " + backColor + " " + border;

 

 

createBox(height, width, backColor, border);

$('xmlResult').innerHTML = resultText;

 

}

 

function createBox(hei,wid,bcolor,brdr)

{

 

boxdiv = document.createElement('div');

boxdiv.style.height = hei

boxdiv.style.width = wid

boxdiv.style.backgroundColor = bcolor

boxdiv.style.border = brdr

document.body.appendChild(boxdiv);

 

}

 

function addText()

{

 

boxdiv.innerHTML = "<h2> My Dynamic Box </h2>";

 

}

 

</script>

 

</head>

 

<body>

 

<input type=button id="click" value="Click" onClick="getXML();">

<div id="xmlResult"></div>

 

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/131526-xml-parsing-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.