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

Java Development

Reply
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Write XML File Fails

I tried reading docs and using XMLWriter but couldn't get it to work after ignoring the "do no call or override" notes in the docs.

Anyway, it was easier to just use string/stringbuffer processing to put "<" around all the fields and concatenate them myself.

I can now verify that I can export data that XMLParser can successfully prarse and reload on the phone. I'm storing the xml

on a server with http post/get but it looks like someone else is discussing the file io for you.

 You can do something like this, where "htmller" changes things like "&" to "&amp;" ,

and probably use stringbuffer or other choices but it really is this easy ,

 

xmldata=xmldata+"<shortcut name=\""+htmller(x.name) + "\" target=\""+htmller(x.tgt.url)+"\">\r\n";

 

parsing is just about as easy but you probably need your own handler.  

 It is pretty easy to just print out the params to the handler methods and figure out empirically what to do,

 

 htmlhandler dh= new htmlhandler(m_app,bmf);

 

ByteArrayInputStream bais= new ByteArrayInputStream(xlmdata);
   XMLParser xml = new XMLParser();
   xml.parse(bais,dh);

 

 

And, of course, do this on a background thread if you suspect your file will get large and notify user as things happen.

 

 

 

Developer
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: Write XML File Fails

_xmlFileName="sample.xml";

 InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );

 

The above code is working fine  but I need the Data Output stream  for the same file in need to include into the application.

 Can any one tellme how to access the file through outputstream. In FileConnection  concept I cant able to access the _xmlFileName 

when the FileConnection need URL  format for the above code in FIleConnection. 

 

please send some samples / code segments if possible

 

 


 

Highlighted
New Developer
Posts: 43
Registered: ‎08-23-2008
My Device: Not Specified

Re: Write XML File Fails

Yes i got the things working for xml file reading and also persistent data storing.
but i dint find the anywhere about the xml file writing /appending.

Also you dint tell me about the data shifting from one device to other.

Example xml

<root>

<emp

<name>kishor</name>
<lname>abc</lname>
</emp>

</root>

This xml file is there in my cod file. when i append it executes with out any exception but no change in the xml file. please assist me doing this.

 DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
InputStream inputStream = getClass().getResourceAsStream( "test.xml" );
Document doc = builder.parse(inputStream);



Node root=doc.createElement("emp");
doc.setNodeValue("NewB");
doc.appendChild(root);

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Write XML File Fails

This probably is not of much help for your immediate problem but generally I've found that trying

to parse a stream, rather than building a DOM, has some benefits in this environment but it depends

on what you are trying to do. If you ever need to plow through a big collection of stuff to find a few things

of interest, it may be of benefit to discard all this stuff ASAP. Obviously, if you control both sides you can

design the xml file to reflect the needs of your app but sometimes there is only so much you can do.

 

Developer
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: Write XML File Fails

Can anyone tellme how to include the xml file into the cod file.

Is it possible to access the xml file as database in Black berry application

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Write XML File Fails

AFAIK just including it on the rapc command line will work, at least it works with png files  but apparently it

does look at the type - not sure if it would try to convert or process it Smiley Happy

 

I posted much earlier on a database related thread but AFAIK no one ever answered. Some DB vendor

showed up, if you can find my earlier post perhaps you can coax the vendor to reply.

 

Personally I'm not sure that a general purpose java DB on a phone is a great way to go and RIM does

have a variety, IIRC, of things like sorted collections that could probably make indexes and of course you have

hash tables etc.

 

Developer
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: Write XML File Fails

can you please send me some samples if possible

XML Database  Demo

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Write XML File Fails

What have you got against a hashtable?

While there are xml db loaders in java,

 

http://www.google.com/search?hl=en&q=java+xml+database+loader&aq=f&oq=

 

the DOM itself could be a reasonable DB if you don't want to use the SAX parser to load your own data

structures on the fly?

 

Sorry if this doesn't help and perhaps for your app you really need a full function database but if you can find the thread

I referenced before there seem to be RIM ports of existing stuff and java is supposed to be platform independent. But, of

course truely indepedent code wouldn't even need a platform ( LOL) and many people write code as if the platform is infinite.

I'd just suggest that you can write more efficient implementations without sacrificing versatility ( it isn't versatile if the

extra stuff uses up all the memory or CPU).

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Write XML File Fails/ OT design philosophy comments

This is a bit OT but it illustrates the motivation behind my constant comments about minimizing resource

waste. Many people, usually people who design Flash Ads and GUI's either don't know or don't care

about CPU, memory,. or bandwith. This was posted on an investment forum earlier,

( contains poorly typed but clear profanity )  

 

http://www1.investorvillage.com/smbd.asp?mb=160&mn=288425&pt=msg&mid=5776133

 

from which you can't conclude " Microsoft Impedes Medical Research" but does make the point that

anytime you add versatility you generally end up using something that someone else may want to use

for something else.

 

So, if you want your app to play nice with other apps, consider something like a hashtable before looking for

a full blown database.

 

Sorry if this is a bit of a design philosophy rant but on constrained resource devices, if you don't have a financial

incentive to upsell phone users,  you have to  be a little more careful with resources.

 

Developer
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: Write XML File Fails

Can you tellme XML File Write / Read possible ways to obtain the process flow operation.?

 

I need to read the file in the resoure itself  and also I need to write the content into it.