Flash vs Silverlight: Random Expand Rotator Silverlight vs Flash: Waving Text
Sep 11

This is a simple demonstration on XML Parsing. It’s a primitive knowledge and I added a drop down effect to make it looks much more attractive.

The Silverlight version can only load the XML from the resources. It’s because I don’t have IIS right now and I couldn’t solve the cross domain security problem (Better don’t waste too much time on that first). Enjoy it.

Comparison

Flash implementation: 1 hour  
Silverlight implementation: 1 hour 30 minutes 
What’s the difference?

  • XML Prasing: XML [AS3] vs XDocument [C#]

Source codes

Flash

Silverlight

XML Prasing: XML [AS3] vs XDocument [C#]

XML is a very difficult topic in many languages, because there are dozen of methods to manipulate XML. If you want to learn something more, here is a good site: http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4. Anyway, let’s have a brief view how did I get all the titles from a RSS feed.

// AS3
// create a loader and load the XML
var loader : URLLoader = new URLLoader();
var request : URLRequest = new URLRequest(url);
loader.addEventListener(Event.COMPLETE, on_complete);
loader.load(request);

// after the request is completed
private function on_complete(e : Event):void{
	var loader:URLLoader = e.target as URLLoader;
	var xmlData : XML = new XML(loader.data);

	var titleList : XMLList = xmlData.channel.item.title;
	for(var i:int = 0; i < titleList.length(); i++){
		var node :XML =  titleList[i];
		// get the title
		var title:String = node.text();
	}
}

You may use LINQ query in C# and the data can be collected easily (if you really know how to use it.)

// C#
// url is the xml data from the xap resources
XDocument xDocument = XDocument.Load(url);
var v = from g in xDocument.Descendants("item")
        select new
        {
            title = g.Element("title").Value,
        };

foreach (var item in v)
{
    string title = item.title.Trim();
}

Shares and Enjoy~

Did you like this post?

Subscribe here:  

19 Responses to “Silverlight vs Flash: Simple XML Parser”

  1. timheuer Says:

    Silverlight also has a SyndicationFeed class for syndication-based information as well.

  2. timheuer Says:

    Actually Silverlight could have loaded your same URI (because it is in the same domain as the XAP being hosted). It could have also loaded remote XML (as can Flash) as long as a policy file exists. Please note that it does NOT have to be IIS on the server at all.

  3. unruledboy Says:

    XmlReader reader = XmlReader.Create(response.GetResponseStream());
    SyndicationFeed feed = SyndicationFeed.Load(reader);
    PostsList.ItemsSource = feed.Items;

    and SyndicationFeed contains a few SyndicationItem

  4. admin Says:

    unruledboy, thank for your suggestion and it’s also good to learn how to parse a XML even it is a syndicate.

    timheur, yup, I know there is policy file. By the way, do you knwo if the policy file will be working even I open the HTML locally? Like if I open the file C:\SilverlightTest.html directly, can it access to the Internet resources?

  5. unruledboy Says:

    forgot to mention, the SyndicationFeed is in the namespace of System.ServiceModel.Syndication

  6. unruledboy Says:

    @admin
    I don’t think it could, I encountered that problem, googled and found a few articles figuring out that the network will not work in local file sysem. you will get the network exception if you try to.

    Tm, please point out if I am wrong.

  7. unruledboy Says:

    sorry, misspelling, Tm->Tim.

  8. admin Says:

    I hope it can work, then I don’t need to setup IIS to debug my application, haha.

  9. Silverlight Cream for Septermber 11, 2008 -- #366 Says:

    [...] Silverlight vs Flash: Simple XML Parser [...]

  10. Matthew Says:

    thank u r information

    it very useful

    u r blog Is very nice

  11. fanboi Says:

    Flash wins 6-0. Silverlight doesn’t even install the correct plugin, no matter what I do.

  12. birdwing Says:

    I think flash has the advantage here.

    It doesn’t load the feed until it knows its completely loaded.
    Which means when the info loads its guaranteed to all be there.

    not really necessary with text, but if your doing something more advanced that’s a larger file size you could run a progress bar for the information very easily in flash. using the getBytesTotal, and getBytesLoaded properties.

    not sure how to do it in silverlight (only took one year of C#), but its another 2 lines of code in flash and you get a preloader for everything loaded without having to make another function for it.

    Plus silverlight has yet to prove it can do something flash cant.

  13. Digitalboon Says:

    WebClient xmlClient = new WebClient();
    xmlClient.DownloadProgressChanged += (s, e) =>
    {
    if (e.BytesReceived == e.TotalBytesToReceive)
    {
    //where done loading
    }
    if (e.ProgressPercentage == 100)
    {
    //where done loading!
    }
    };

    You can configure a loading sequence for larger files with Silverlight too =D

  14. GMK HUSSAIN Says:

    Flash is Best

  15. sandrar Says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  16. admin Says:

    Hi sandrar, thank you. Glad to know that you love it so much!

  17. Audrey Cannon Says:

    I really loved this amazing article. Please keep it up. Greets!.

  18. Flash ve Silverlight karşılaştırması | AdobeHaber Says:

    [...] Flash Silverlight Download [...]

  19. celebrity fuck you Says:

    Sign: zdbrw Hello!!! vueqy and 706edxnfannuc and 5845 : Great!

Leave a Reply