You guys might know the importance of XML, XML (Extensible Markup Language) is a flexible markup language, meant to store, carry, and exchange data. We can make use of XML as a simple database to store data and retrieve data.
In this tutorial, you guys can learn how we can read XML data using XMLHttpRequest (Adobe AIR Application). Here is my sample XML data (empDetails.xml), I have created one root node called<employee> , in that I have created a node called <emp> and it has got one attribute called “id” and has got several child nodes like <name>, <designation>, <phone>. Now we have read these nodes using XMLHttpRequest and we need to display the same.
<employee> <emp id="1007"> <name>John Chamber</name> <designation>Web Expert</designation> <phone>555-55-555</phone> </emp> </employee>
Here is the code for reading XML data using XMLHttpRequest:
<script>
var xmlFile = null;
var xmlObj = null;
function doLoad()
{
xmlFile = air.File.applicationResourceDirectory.resolve("empDetails.xml");
xmlObj = new XMLHttpRequest();
xmlObj.onreadystatechange = function()
{
var elem = null;
var name = null;
var designation = null;
var phone = null;
var rootNode = null;
if( xmlObj.readyState == 4 )
{
rootNode = xmlObj.responseXML.documentElement.getElementsByTagName( "emp" );
for( var i = 0; i < rootNode.length; i++ )
{
name = rootNode[i].getElementsByTagName("name")[0].textContent;
designation = rootNode[i].getElementsByTagName("designation")[0].textContent;
phone = rootNode[i].getElementsByTagName("phone")[0].textContent;
elem = document.createElement("div");
elem.innerText = name + " " + designation;
document.body.appendChild(elem);
}
}
}
xmlObj.open( "GET", xmlFile.url, true );
xmlObj.send( null );
}
</script>
Hope the above code will helps the people who are working on Adobe AIR Applications. Cheers Guys!! Enjoy the World of Web!!
Related Entries...
AIR is rocking in the web world, if you guys! Search for Adobe AIR you will get tons of web snippets ...
I am back again with some helpful snippet code. Here using JavaScript we can pro actively sort date f ...
John Resig, has explained us a better and interesting way of Method Overloading. Here he has discusse ...
As we all know AJAX is rocking the Web World all around, just I had a thought to developer a simple A ...
Hey folks, hmmm... How can I start.... !!! Yeah, well folks... below is very simple snippet code for ...
Making a preloader in flash is very simple. By using ProgressBar and Image Loader components, we can ...
After going through this article, you will get an idea on resolving browser compatibility issues whil ...
The Sprite class is new in ActionScript 3.0, This class is a basic display list building block, which ...
Below is the code which is written in JavaScript, we can use this script for bookmarking the particul ...
Hi Guys, I would like to share a JavaScript snippet code which will remove special characters (like ! ...























6 Responses
[...] Using XMLHttpRequest, reading XML data (Adobe AIR Application) » This Summary is from an article posted at Developer Snippets on Sunday, August 19, 2007 You [...]
[...] Tutorials @ http://www.developersnippets.com/2007/08/19/using-xmlhttprequest-reading-xml-data-adobe-air-applicat... [...]
Hi Vivek,
Good article.. you have explained and given good ready to use code…
Hi, thanks for the example, but can you please tell what is this variable “air” is? where does it come from? it is undefined if I try to use it… And your is not the 1at snippet where I ask myself thie question…..
Thank you very much
Natalia
Hi Natalia,
Thanks for posting your comments for this article, in the above example “air” is the parent class from which we are creating an object called “xmlFile”. I am thinking that you might be knowing about what is a ‘parent class’
Thanks,
Vivek
[...] 2. Using XMLHttpRequest, reading XML data (Adobe AIR Application) [...]