Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Monday, August 01, 2016

Android: SQLite database and ListView

Reading data from SQLite database and using it in ListView

Android: parsing XML and JSON

Parsing XML content


sample XML data:
<channel>
<title>Singapore - Nowcast and Forecast</title>
<description>3 hour Forecast</description>
<item>
<title>Nowcast Table</title>
<category>Singapore Weather Conditions</category>
<weatherForecast>
<area name="ANG MO KIO" forecast="Partly cloudy " icon="PC" zone="C" lat="1.37000000" lon="103.84940000"/>
<area name="BEDOK" forecast="Partly cloudy " icon="PC" zone="E" lat="1.32403830" lon="103.92003560"/>
<area name="BISHAN" forecast="Partly cloudy " icon="PC" zone="C" lat="1.35120000" lon="103.84850000"/>
<area name="BUKIT BATOK" forecast="Partly cloudy " icon="PC" zone="W" lat="1.34910000" lon="103.74970000"/>
<area name="BUKIT PANJANG" forecast="Showers " icon="SH" zone="C" lat="1.38080000" lon="103.76250000"/>
</weatherForecast>
</item>

</channel>

Parsing JSON


Sample JSON data: 
{"coord":{"lon":103.85,"lat":1.29},"weather":[{"id":803, "main":"Clouds", "description":"broken clouds", "icon":"04d"}],"base":"cmc stations","main":{"temp":31.97, "pressure":1010, "humidity":63, "temp_min":31, "temp_max":33},"wind":{"speed":5.7,"deg":80},"clouds":{"all":75}, "dt":1451979432, "sys": {"type":1, "id":8143, "message":0.0033, "country":"SG", "sunrise":1451948892, "sunset":1451992281},"id":1880252,"name":"Singapore","cod":200}

Android: getting and reading online content


Setting up: XML, manifest


Fetching the content from URL using a background task


Reading the fetched content using Stream readers.

Android videos: Activity, Button, onClick

How to create a new Activity in android studio

Create a button and make it do something when clicked

How to go to a new Activity when a button is clicked

Saturday, April 21, 2012

javascript: String to XML

a quick utility function to convert from string to xml object.
Reference:
http://www.w3schools.com/xml/xml_dom.asp

function stringToXML(text)
{
var xmldoc;
if (window.DOMParser)
{
 var parser=new DOMParser();
 xmldoc=parser.parseFromString(text,"text/xml");
}
else // Internet Explorer
{
 xmldoc=new ActiveXObject("Microsoft.XMLDOM");
 xmldoc.async=false;
 xmldoc.loadXML(text);
}
return xmldoc;
}

Useful properties/methods for XML Object:

  • getElementsByTagName(tagName)
  • childNodes[index]
  • nodeValue
  • getAttribute(atttributeName)
  • setAttribute(name, value)
  • createElement(name)
  • createTextNode(text)
  • appendChild(element)
  • removeChild(element)