
June 6th, 2012, 09:17 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Location: Western Isle of Scotland
|
|
|
URL Request
Can you help me out, I'm new to C#.
I'm load an XML doc into a webpage using C# and I'm wondering how I can load specific IDs from my XML doc. i.e
Default.aspx?ID=2008 will load 2008 data
here's my code so far
XML doc
Code:
<?xml version="1.0" encoding="utf-8" ?>
<mainTemplate>
<item ID="2008">
<type >video</type>
<thumb>thumbs/2008/01.jpg</thumb>
<main>video/videos2008/2008 01.flv</main>
<title>An Iar Chuairt Dheireannach</title>
<description><![CDATA[<b>Josie Burgess</b> - Airson]]></description>
<school>Sgoil Lìonacleit</school>
<topic>Bu chòir do dh'Albha bhith seasamh leatha fhèin aig na h-Olympics</topic>
</item>
<item ID="2009">
<type>video</type>
<thumb>thumbs/2009/02.jpg</thumb>
<main>video/videos2009/2009 02.flv</main>
<title>An Iar Chuairt Dheireannach</title>
<description><![CDATA[<b>Anna McMullen</b> - An aghaidh]]></description>
<school>Àrdsgoil Phort Rìgh</school>
<topic>Bu chòir lan shaorsa a bhith aig na meadhanan leigeil le daoine am beachdan a chur an ceill</topic>
</item>
<item ID="2010">
<type>video</type>
<thumb>thumbs/2010/06.jpg</thumb>
<main>video/videos2010/2010 06.flv</main>
<title>An Iar Chuairt Dheireannach</title>
<description><![CDATA[<b>Corrin Miller</b> - An aghaidh]]></description>
<school>Acadamaidh Rìoghail Inbhir nis</school>
<topic>Chan ann airson beatha-cosnaidh a bu chòir do sgoiltean a bhith ag ullachadh sgoilearan idir</topic>
</item>
ETC
Default.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.XPath;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("App_Data/XMLcat01.xml"));
XmlNodeList nodes = doc.SelectNodes("mainTemplate/item");
Repeater2.DataSourceID = null;
Repeater2.DataSource = nodes;
Repeater2.DataBind();
String UserID = Request.QueryString["ID"];
Response.Write("id detected = " + UserID);
}
}
Default.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.lightbox-0.5.js" type="text/javascript"></script>
<link href="css/jquery.lightbox-0.5.css" rel="stylesheet" type="text/css" />
<link href="css/thumbs.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("#images a").lightBox({ fixedNavigation: true });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
</asp:XmlDataSource>
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="XmlDataSource1">
<ItemTemplate>
<div id="images">
<div style="width:573px">
<div id="data">
<ul id="pic">
<li><%#((System.Xml.XmlNode)Container.DataItem).Attributes["ID"].Value %></li>
<li><a href="<%#XPath("main")%>"/><img src="<%#XPath("thumb")%>"/></a></li>
<li><%#XPath("title")%></li>
<li><%#XPath("description")%></li>
</ul>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
|