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
Simple XML Parser [Flash 9, AS3] (26.9 KiB, 1,701 hits)
Simple XML Parser [Silverlight 2, C#] (94.6 KiB, 2,055 hits)
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();
}

September 11th, 2008 at 6:55 am
Silverlight also has a SyndicationFeed class for syndication-based information as well.
September 11th, 2008 at 6:57 am
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.
September 11th, 2008 at 10:08 am
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed feed = SyndicationFeed.Load(reader);
PostsList.ItemsSource = feed.Items;
and SyndicationFeed contains a few SyndicationItem
September 11th, 2008 at 12:44 pm
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?
September 11th, 2008 at 4:08 pm
forgot to mention, the SyndicationFeed is in the namespace of System.ServiceModel.Syndication
September 11th, 2008 at 4:11 pm
@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.
September 11th, 2008 at 4:12 pm
sorry, misspelling, Tm->Tim.
September 11th, 2008 at 4:45 pm
I hope it can work, then I don’t need to setup IIS to debug my application, haha.
September 15th, 2008 at 8:50 pm
[...] Silverlight vs Flash: Simple XML Parser [...]
October 15th, 2008 at 7:40 pm
thank u r information
it very useful
u r blog Is very nice
October 25th, 2008 at 12:52 am
Flash wins 6-0. Silverlight doesn’t even install the correct plugin, no matter what I do.
November 19th, 2008 at 9:44 am
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.
April 29th, 2009 at 4:33 am
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
July 10th, 2009 at 11:42 am
Flash is Best
September 10th, 2009 at 5:34 pm
Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.
September 11th, 2009 at 1:47 am
Hi sandrar, thank you. Glad to know that you love it so much!
January 8th, 2010 at 8:01 pm
I really loved this amazing article. Please keep it up. Greets!.
July 13th, 2010 at 9:28 am
[...] Flash Silverlight Download [...]
August 24th, 2010 at 2:29 pm
Sign: zdbrw Hello!!! vueqy and 706edxnfannuc and 5845 : Great!