Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to load and parse XML files

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.

Article Metadata
Platform(s): Flash Lite 2.x
Created: soueldi (31 May 2007)
Last edited: hamishwillee (14 May 2013)

Warning.pngWarning: This application fails when trying to establish a network connection on the N95 (FL 2.0)

We will be using this basic XML document:

<modelName>Nokia N73</modelName>
<type>ARM 9</type>

Loading XML files

This following script loads an XML file:

// create a new XML object
var myPhoneXML = new XML();
//Text nodes that contain only white space are discarded
myPhoneXML.ignoreWhite = true;
// define the onload handler
myPhoneXML.onLoad = function(success) {
if (success) {
trace("XML loaded");
} else {
trace("Loading failed");
// load the XML file into the myPhoneXML object
  • The load() method on the XML object allows you to download data from a remote host.
  • When the data has finished downloading, the onLoad event of the XML object occurs.

XML Navigation

  • firstChild: The first child in the parent node's child list
// Output: <myPhone>[...]</myPhone>
// Output: <modelName>[...]</modelName>

  • lastChild: The last child in the parent node's child list
// Output: <cpu>[...]</cpu>

  • nextSibling: The next node in the parent node's child list
// Output: <screen>[...]</screen>

  • previousSibling: The previous node in the parent node's child list

Xml nav.jpg

Getting nodes value

  • This example checks the <clock_rate> node value:
// Output: 220

  • Another example using user XMLNode objects to get the screen resolution
var screenNode:XMLNode = myPhoneXML.firstChild.firstChild.nextSibling;
trace("Resolution: " + screenNode.firstChild.firstChild.nodeValue + " x " +
// Output: Resolution: 240 x 320
  • Another example by iterating through the child nodes
for (var aNode:XMLNode = myPhoneXML.firstChild.firstChild.nextSibling.firstChild;aNode != null;aNode=aNode.nextSibling) {
// Output: 240
// 320
This page was last modified on 14 May 2013, at 05:07.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.