. Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Monday, November 21, 2005

Amazon Search in XAML

I have just been playing with some XAML databinding. I was interested by the Channel 9 Example which creates an RSS reader in just a couple of lines of XAML

I hooked it up to Amazons REST API. I had a couple of problems with it that I will go into later. But what follows is the XAML that I used [also it can be downloaded from my server]:


<StackPanel
xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" Margin="10">
<StackPanel.Resources>
<XmlDataNamespaceManager x:Key="NS">
<XmlNamespace Prefix="a"
Uri
="http://webservices.amazon.com/ AWSECommerceService /2005-10-05" />
</XmlDataNamespaceManager>
<XmlDataSource x:Key="Amazon" XmlNamespaceManager="{StaticResource NS}"
Source="http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService&
AssociateTag=cnetfra-21& AWSAccessKeyId=[SUBSCRIPTION ID]&
SearchIndex=Books& Keywords=AJAX& BrowseNode=71& ResponseGroup=Request,Large,Images& Sort=salesrank& Operation=ItemSearch"
/>

<DataTemplate x:Key="TitleTemplate">
<TextBlock TextContent="{Binding XPath=a:ASIN}" />
</DataTemplate>
</StackPanel.Resources>

<Label Content="{Binding Source={StaticResource Amazon}, XPath=/a:ItemSearchResponse/a:OperationRequest/ a:HTTPHeaders/a:Header/@Name}" FontSize="24" FontWeight="Bold" />

<DockPanel DataContext="{Binding Source={StaticResource Amazon},
XPath=/a:ItemSearchResponse/a:Items/a:Item}"
Height="300px" >
<ListBox DockPanel.Dock="Left" Binding.XmlNamespaceManager="{StaticResource NS}"
ItemsSource="{Binding}" ItemTemplate="{StaticResource TitleTemplate}" IsSynchronizedWithCurrentItem="True" />
<TextBox Name="Contents" Text="{Binding XPath=a:ItemAttributes/a:Title}" Wrap="True" Width="Auto" />
</DockPanel>
</StackPanel>

The major problem that I had was that the AMAZON API has a default namespace, therefore to be able to use XPath against the datasource you need to include a NamespaceManager so that the XPath queries are resolved correctly. Once this is done everything is really simple.

Now this example I have created leaves a lot to be desired, but you can see how easy it to create.

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed]

Related Wikipedia Documents
, , , , , , , , , , , , ,

My Related Documents
, , , ,

Related Amazon Books
Programming Windows Presentation Foundation: /, Service-Oriented Architecture: Concepts, Technology, and Design: /, Service-oriented Architecture: A Field Guide to Integrating XML and Web Services: /, Mining Amazon Web Services: Building Applications with the Amazon API: /, Professional Web APIs with PHP: Google, EBay, Paypal, Amazon, Yahoo, Fedex: /, Amazon Hacks: /, MCAD Training Guide 70-320: Developing XML Web Services and Server Components with Visual C#.NET and the .NET Framework: /, Expert Service-Oriented Architecture in C#: Using the Web Services Enhancements 2.0: /, RSS and Atom Hacks: /, RSS and Atom: Understanding and Implementing Content Feeds and Syndication: /

Related Images From Flickr

Comments: [Add New]

Nice script.
Do you know if this type of script will work on live.com via WPF/E or jolt?

slyi

By Anonymous, at Wednesday, November 23, 2005 1:38:00 PM