Load XML in webOS

Read XML in webOS

Refer Palm App :Basic App for Creating a basic App

Step1 : Create a folder named “Data” and paste test.xml

Test.XML

<l>
<citem>
<id>1</id>
<userId>rrrtttt1111117779999999999999</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>2</id>
<userId>111111aaa</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>3</id>
<userId>333333333</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>4</id>
<userId>33333333311111111</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>5</id>
<userId>Laaaaa222222</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>6</id>
<userId>11111111qqqqq333333333</userId>
<pwd>adsdasdasd</pwd>
</citem>
<citem>
<id>7</id>
<userId>456</userId>
<pwd/>
</citem>
<citem>
<id>8</id>
<userId>tyrrr</userId>
<pwd></pwd>
</citem>
</l>

Step 2: In Scene1-scene.html , Include another <div> tag to load the XML data

<div id=”XMLData”></div>

Entire Code of Scene1-scene.html will look like below

<div id=”main” class=”palm-hasheader”>

<div class=”palm-header”>Header</div>

<div id=”count” class=”palm-body-text”>Hello World</div>

<div id=”XMLData”></div>

</div>

Step 3: Scene1-scene.html corresponding javascript file is
Scene1.assistant.js. Whatever javascript related to this scene can go in to this
javascript

Each javascript file has four events (Setup / Activate /cleanUp /deactivate)
related to the scene

1. Scene1-assistant.js

2. Edit the setup function to contain the following:

Scene1Assistant.prototype.setup = function() {

xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange=handler

xmlhttp.open(“GET”,”Data/test.xml”);

xmlhttp.send();

};

3. Add the following funtion

function handler()
{
if(this.readyState == 4 && (this.status == 200 || this.status == 304))
{
if(this.responseXML != null)
{
xmlDoc=this.responseXML
document.getElementById(“XMLData”).innerText=this.responseText  //It loads the XML content and writes into the DIV tag with ID XMLData}
}
}

Output

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.