.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 6th, 2012, 09:17 AM
slaine slaine is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Western Isle of Scotland
Posts: 250 slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 9 h 18 m 20 sec
Reputation Power: 15
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>

Reply With Quote
  #2  
Old June 6th, 2012, 05:34 PM
requinix's Avatar
requinix requinix is offline
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,855 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 4 h 51 m 44 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
An XPath expression (which is what SelectNodes() takes) that will find a specific node according to its "ID" attribute is
Code:
mainTemplate/item[@ID=123]

(substitute 123 for the actual number, of course)

Remember to make sure that UserID is actually a number - don't want to use just any string in there.

Reply With Quote
  #3  
Old June 7th, 2012, 02:26 AM
slaine slaine is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Western Isle of Scotland
Posts: 250 slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level)slaine User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 9 h 18 m 20 sec
Reputation Power: 15
Quote:
Originally Posted by requinix
An XPath expression (which is what SelectNodes() takes) that will find a specific node according to its "ID" attribute is
Code:
mainTemplate/item[@ID=123]

(substitute 123 for the actual number, of course)

Remember to make sure that UserID is actually a number - don't want to use just any string in there.


Thanks you

sovled

here's the script
Code:
        String UserID = Request.QueryString["ID"];

        XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("App_Data/XMLcat01.xml"));
        XmlNodeList nodes = doc.SelectNodes("mainTemplate/item[@ID='"+ UserID +"']");

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > URL Request

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap