Solved

Syntax check - using xpath in repeater efficiently?

Posted on 2008-06-24
2
327 Views
Last Modified: 2013-11-07
Hi,
I finally got my basic syntex working and just wanted to know it I have if completed in the most effiecent way or is there a better /cleaner way that I should look at.  The XML files are pretty small.

<asp:Repeater ID="Repeater1" DataSourceID="XmlSource" runat="server">
  <ItemTemplate>
    <h1><%# Xpath ("../@heading") %></h1>
    <div class="feature">
      <h2>Latest: <%# XPath ("@title") %></h2>
      <img src="<%# XPath ("thumbnail") %>" alt="4wd photo" width="100" height="100"/>
      <p><%# XPath ("summary") %></p>
    <p class="smaller">  
    <%# XPath ("author", "By {0} :: ") %> <%# XPath ("pubDate", "Published: {0}. " ) %>  <%# XPath ("@url","<a href='{0}'>Read more &gt;&gt;</a>" ) %>
    <br class="clearfloat" />    </p>    
    </div>
  </ItemTemplate>
</asp:Repeater>

 <asp:XmlDataSource id="XmlSource" DataFile="/App_Data/articleXML.xml" runat="server" XPath="articles/subject[@category='4wd']/article[feature='yes']" />


<articles>
  <subject category="4wd" heading="4wd Driving Articles">
    <article title="More than Just Rubber" url="/4wd/4wd_tyres_more_than_rubber.asp">
      <feature>yes</feature>
      <pubDate>Jan 2007</pubDate>
      <author>Mick Farmer</author>
      <thumbnail value="yes">/assets/tb_tyre.jpg</thumbnail>
      <summary>I was inspired to revisit this subject by a "late night" conversation with friends who had just fitted cross ply tyres to their vehicles without realising it.</summary>
    </article>
    <article title="Winches - Do You Need One?" url="/4wd/4wd_winches.asp">
      <feature>no</feature>
      <pubDate>Nov 2005</pubDate>
      <updated value="true">Feb 2008</updated>
      <author>Mick Farmer</author>
      <thumbnail value="yes">/assets/tb_winch.jpg</thumbnail>
      <summary>Picking recovery equipment for your vehicle is a bit like selecting a 4wd. First, you need to examine where, when and what are you going to be doing - then select the equipment most suitable.</summary>
    </article>
....

I will try to move towards Linq in the next few months but finding it tough after finally understanding xpath (a little!).  But for now ...

Cheers
Tania

0
Comment
Question by:Tania_Farmer
2 Comments
 
LVL 3

Accepted Solution

by:
maliger earned 250 total points
Comment Utility
I don't see anything wrong or inefficient in your solution. Nice job!
0
 

Author Comment

by:Tania_Farmer
Comment Utility
Thanks.
Tania
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now