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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.