Solved

Syntax check - using xpath in repeater efficiently?

Posted on 2008-06-24
2
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

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

Author Comment

by:Tania_Farmer
ID: 21862940
Thanks.
Tania
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…

752 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