Xml objects

From iRidium Mobile Wiki
Jump to: navigation, search

DOWNLOAD: Example of a project


Description

In iRidumScript you can create and edit xml-objects and also refer and manipulate each field of the object. To create xml-objects use the command:

xmlObject = new XML('<test atrib="123">text</test>');

  • xmlObject - the variable which we assign the xml-type for and where we write xml-structure
  • <test atrib="123">text</test> - data which are going to be stored in the objects as fields and values


var DEVICE = IR.GetDevice("Weather"); //Defint the driver for working with weather data

var xml;       //the variable stores the xml-object

//---------------------------------------------------
//block for activation of user variables
//---------------------------------------------------
var City;     
var Region;   
var Country;  
var Temperature; 
var Distance;
var Pressure;
var Speed;
var Chill;
var Direction;
var SpeedNumber;
var Humidity;
var Visibility;
var Pressure;
var Rising;
var Sunrise;
var Sunset;

//---------------------------------------------------

IR.AddListener(IR.EVENT_RECEIVE_TEXT, DEVICE, function(text) //Event is activated when data come from the server
{
  
  xml = new XML(text); //Convert data received from the server into the xml-оbject
  
//---------------------------------------------------
//Writing xml-attribute into the corresponding variables
//---------------------------------------------------
  
  City = xml.rss.channel["yweather:location"]["@city"]; //Writing the city name  into the variable
  
  Region = xml.rss.channel["yweather:location"]["@region"]; //Writing the region name  into the variable 
  
  Country = xml.rss.channel["yweather:location"]["@country"]; //Writing the country name  into the variable 
  
  Temperature = xml.rss.channel["yweather:units"]["@temperature"];//Writing the type of displaying the weather into the variable
  
  Distance = xml.rss.channel["yweather:units"]["@distance"]; //Writing the units of speed measurement into the variable 
  
  Pressure = xml.rss.channel["yweather:units"]["@pressure"]; //Writing the pressure value into the variable 
  
  Speed = xml.rss.channel["yweather:units"]["@speed"]; //Writing the speed value into the variable 
  
  Chill = xml.rss.channel["yweather:wind"]["@chill"]; //Writing the temperature value into the variable 
  
  Direction = xml.rss.channel["yweather:wind"]["@direction"]; //Writing the wind direction into the variable 
  
  SpeedNumber = xml.rss.channel["yweather:wind"]["@speed"]; //Writing the wind speed into the variable 
  
//---------------------------------------------------
//Output of received data in the log
//---------------------------------------------------
  
  IR.Log("City = "+City);
  
  IR.Log("Region = "+Region);
  
  IR.Log("Country = "+Country);
  
  IR.Log("Temperature = "+Temperature);
  
  IR.Log("Distance = "+Distance);
  
  IR.Log("Pressure = "+Pressure);
  
  IR.Log("Speed = "+Speed);
  
  IR.Log("Chill = "+Chill);
  
  IR.Log("Direction = "+Direction);
  
  IR.Log("SpeedNumber = "+SpeedNumber);

});


DOWNLOAD: Example of a project