开发者

Get all <image> nodes from an xml using xpath and a asp.net repeater

I have a repeater with an xmlDataSource. What I need is very simple, but i can't make it happen. Using this xml file I want to display all the nodes from the project "ProjectOne".

<?xml version="1.0" encoding="utf-8" ?>
<projects>
<project name="ProjectOne">
    <description>this is the description</description>
    <image>image1</image>
    <image>image2</image>
    <image>image3</image>
</project>
<project name="ProjectTwo">
    <description>this is the description</description>
    <image>image1</image>
</project>

I'm using this repeater with an xmlDataSource.开发者_如何学Go But it only shows the first image node (image1) instead of showing all the nodes (image1 + image2 + image3)

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1"  >
<ItemTemplate>
    <div>
        <img src='<%#XPath("image")%>' alt='test' />
    </div>
</ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="App_Data/ProjectsPosta.xml" XPath="projects/project[@name='ProyectOne'] " />

I want to do it without touching the .cs if it's possible

Any idea??

Thanks


I don't know much about ASP repeater, but knowing XPath, here's what I would try:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1"  >
  <ItemTemplate>
    <div>
        <img src='<%#XPath(".")%>' alt='test' />
    </div>
  </ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
      DataFile="App_Data/ProjectsPosta.xml"
      XPath="projects/project[@name='ProjectOne']/image" />

Note the change of 'ProyectOne' to 'ProjectOne'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜