Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 17
Registered: ‎01-07-2010
My Device: Not Specified
Accepted Solution

read data from xml file

Hi all,

 

I have an xml file store on my bb.

How can I read data inside tag? I think that one way is using  blackberry.find.FilterExpression(), as the sample below. I don't know how.... but it doesn't matter. I will try!!

function handleOpenedFile(fullPath, blobData) {

    temp = blackberry.utils.blobToString(blobData);

   //var NomeOperatore = blackberry.find.FilterExpression('');
}

function readPianoViaggi() {
    if (blackberry.io.file.exists(filePath)) {
        blackberry.io.file.copy(filePath, filePath2);
        blackberry.io.file.readFile(filePath, handleOpenedFile);
        
    }
}

 

 

 my question is: can I read data inside tag using an operation like 

var itemDescription = temp.getElementsByTagName('NomeOperatore')[0].firstChild.data or something similar?

 

thanks

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: read data from xml file

[ Edited ]

You would be looking at doing something like the following.. I'm not sure if all of my syntax is correct  Smiley Happy

 

 

function readFile() {
  blackberry.io.file.readFile("file:///store/home/user/sample.xml",handleOpenedFile);
}
  

function handleOpenedFile(fullPath, blobData)
{
  var xmlString = blackberry.utils.blobToString(blobData, null);
  var parser = new DOMParser();
  var doc = parser.parseFromString(xmlString, "text/xml");

  var itemDescription = doc.getElementsByTagName('NomeOperatore')[0].firstChild.data;
}

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 17
Registered: ‎01-07-2010
My Device: Not Specified

Re: read data from xml file

Hi!!!

I've changed only this instruction:

 

var xmlString = blackberry.utils.blobToString(blobData,"UTF-8");

 

thanks!!! thanks!!! thanks!!!!