XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 14th, 2011, 05:40 AM
jason_moutia jason_moutia is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 24 jason_moutia New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 6 h 55 m 3 sec
Reputation Power: 0
NodeValue problem

Hi guys I'm new to xml and I'm struggling on this one. Below are my html and xml file.

HTML CODE
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Checking temperatures</title>

    <script language = "javascript">
      function getDoc()
      {	 

      if (window.XMLHttpRequest) {
          request = new XMLHttpRequest();
       } 
	   else if (window.ActiveXObject) {
          request = new ActiveXObject("Microsoft.XMLHTTP");
        }
	    if (request.overrideMimeType) {         
		  request.overrideMimeType("text/xml");
		}

        if(request) {
          request.open("GET", "temperatures.xml", true); 

          request.onreadystatechange = function() 
		  
          { 
            if ((request.readyState == 4) && (request.status == 200)) { 
            var xmlDocument = request.responseXML;
			findClass(xmlDocument);
            }
           
          } 
		  request.send(null); 
          } 
		  
      }
	  
	  function findClass(doc) {
	  
	  var sum = 0;	
	  var temp = doc.getElementsByTagName('temperature');
	  for (i=0; i<temp.length; i++) {
	    var day = temp[i].getElementsByTagName('day');
	    var dayValue = day[0].firstChild.nodeValue;
	    var month = temp[i].getElementsByTagName('month');
	    var monthValue = month[0].firstChild.nodeValue;
	    var year = temp[i].getElementsByTagName('year');
	    var yearValue = year[0].firstChild.nodeValue;
           var max = temp[i].getElementsByTagName('max_temperature');
	    var maxValue = max[0].firstChild.nodeValue;
	    	
	    sum = sum + maxValue;	
	    var displaytemp = dayValue + "/" + monthValue + "/" + yearValue + " : " + maxValue + " " + sum;
	  
	    var myEl = document.createElement('p');
        var myTx = document.createTextNode(displaytemp);
	
        myEl.appendChild(myTx);
	
        var temperature = document.getElementById('title1');
	
        temperature.appendChild(myEl);
	} 
}
 
</script>

</head>

 <body>

    <h1>Checking temperatures</h1>
    <form>
      <input type = "button" id="reqDoc" value = "Check temperatures"> 
    </form>
<script type="text/javascript">
var myDoc = document.getElementById('reqDoc');
myDoc.onclick = getDoc;
</script>
<div id="title1"></div>
</body>
</html>


XML FILE
Code:
<?xml version="1.0"?>
<temperatures>
	<temperature>
		<day>1</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>24.0</max_temperature>
	</temperature>
	<temperature>
		<day>2</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>21.9</max_temperature>
	</temperature>
	<temperature>
		<day>3</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>24.4</max_temperature>
	</temperature>
	<temperature>
		<day>4</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>25.8</max_temperature>
	</temperature>
	<temperature>
		<day>5</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>26.9</max_temperature>
	</temperature>
	<temperature>
		<day>6</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>25.3</max_temperature>
	</temperature>
	<temperature>
		<day>7</day>
		<month>4</month>
		<year>2010</year>
		<max_temperature>25.7</max_temperature>
	</temperature>
</temperatures>


In my html file, when I try to add maxValue to sum it doesn't work.

example:
sum = 10;
maxValue = 24.0;

sum = sum + maxValue;

Output is 1024.0 instead of 34.0

My question is how can I get the maxValue to be parse as an integer so as I can add it to sum. I only want to use DOM to achieve that and not using XSLT.

If anyone can help. thanks in advance.

Reply With Quote
  #2  
Old April 14th, 2011, 07:03 AM
jason_moutia jason_moutia is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 24 jason_moutia New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 6 h 55 m 3 sec
Reputation Power: 0
I find a solution. I use parseFloat to convert maxValue into integer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > NodeValue problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap