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

Adobe AIR Development

Reply
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: Lots of Data- What to do?

Yes, that I agree with, can you Embed the XML file and parse it using XML(); ? or should it be a xml with .txt extension?
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Highlighted
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Lots of Data- What to do?

The file extension should be irrelevant.  The mimetype may be more important.

 

A simple text embed as I showed earlier would work, with the results of toString() being passed to XML().  It can take numerous types and convert them.

 

If you data might contain any Unicode information, you'd want to pay particular attention to encoding issues.  Generally the file would probably be UTF-8 encoded, so then you might need to use readUTF() on the object retrieved from the embed class.  To avoid future problems, you should probably just start with that one, unless you know you will have a different encoding.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: Lots of Data- What to do?

[ Edited ]

So my code is pretty much as follows for searchers looking for solutions:

package
{
	import flash.utils.ByteArray;
	import qnx.ui.text.Label;
	
	public class MYXML extends Sprite
	{
		super();
                private var E1 = String: new String('string');
		[Embed('MyXML.xml', mimeType='application/octet-stream')]
		private var MyXMLFILE:Class; 
		private var EleXML:XML;
		public function obtainXML():void {
			var ba:ByteArray = new MyXMLFILE();
			var st:String = ba.readUTFBytes(ba.length);
			EleXML = new XML(st);
		}
		obtainXML();
		var idlabel :Label = new Label();
		idlabel.text = 'Informative information';
		idlabel.format = new TextFormat( null, 14, 0xFFFFFF );
		idlabel.x = 200;
		idlabel.y = 20;
		idlabel.width  = idlabel.textWidth + 5;
		idlabel.height = idlabel.textHeight + 5;
		this.addChild( idlabel );
		DisplayInfo();
		
		private function DisplayInfo():void{
			var EN:Label = new Label();
			var ESTRING:String = new String( E1 );
			var cSTRING:String = new String();
			trace(EleXML.Element.(@symbol == ESTRING));
			cSTRING = EleXML.Element.More.fact1.text();
			EN.text = cSTRING;
			EN.width = EN.textWidth + 5;
			EN.x = 90;
			EN.y = 90;
			addChild(EN);
		}
		
	}
}

 

Sorry I forgot to add the xml...

 

<?xml version="1.0" encoding="utf-8"?>
<Element symbol="string">
	<More>
      	<fact1>This is an element in an element</fact1>
	<fact2>This is another element</fact2>
	<fact3>This is fact</fact3>
	</More>
</Element>
<Element symbol="notastring">
	<More>
      	<fact1>This will not return true</fact1>
	<fact2>This is not fact</fact2>
	<fact3>It will come true if you search for @symbol == "notastring" </fact3>
	</More>
</Element>

 

This should work perfectly with the above xml/as3 code.

 

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 386
Registered: ‎12-12-2010
My Device: BB Style
My Carrier: Sprint

Re: Lots of Data- What to do?

Thanks tensioncore... for the sake of completeness..could you also post a sample xml file that goes with this code. 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Lots of Data- What to do?

Tensioncore, kditty, and I did additional experimentation in the IRC chat (#playbook-dev on irc.freenode.net) and discovered a few related items.

 

For one thing, in spite of advice you can find on the web that mimeType of "text/xml" does something useful, it appears either to be unsupported, or broken.  Certainly Adobe says it's not one of the select supported types.

 

Also, the ByteArray.readUTFBytes() approach doesn't appear to be the only way to do it.  The following variation works fine as well:

 

[Embed('MyXML.xml', mimeType='application/octet-stream')]
private var MyXMLFILE:Class; 

...

var EleXML:XML = XML(new MyXMLFILE());

Not that both approaches are creating (apparently.. the docs aren't exactly good on this) something called a ByteArrayAsset object when you do "new MyXMLFILE()", which supports pretty much all the ByteArray methods.

 

 

In this case, however, you're relying on the XML() call's ability to call toString() on the object passed (also undocumented, but it does take numerous types of input and converts them to strings to parse them).  Note also that I'm using just "XML()" above instead of "new XML()"... there's no real difference in these cases (the function effectively calls new XML for you, and returns the result).

 

Both approaches appear to ignore any encoding="" attribute that you might have in your <?xml ?> tag, and treat it always as UTF-8 encoded data (at least in my experiments).

 

Lastly, although I've seen blogs saying that hardcoding the XML directly into your source code will compress it better than using Embed, my experiments show that in fact the data in the embedded XML above will be compressed quite efficiently, so you should have no worries about doing this and in fact, it's a rather nice way to get data like this into an app.  I took one file with a line of 99 characters of text, and cloned the line 999 times (for a data size of about 10K).  The resulting SWF grew only about 50 bytes...  (I tried again with random data and it was 10K bigger, so that's conclusive.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: Lots of Data- What to do?


tags07 wrote:

Thanks tensioncore... for the sake of completeness..could you also post a sample xml file that goes with this code. 


Thanks for helping me teach! It helps the learning!
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting