473,769 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't it show the rest of the XML file?

Hello,

I am just trying out reading an XML file in an ASP.NET page, but am
having a little trouble. I'm sure this is something really obvious and
dumb, but I can't see what ...

I have an XML file that contains some site map info (see further down),
and I have written a page to read this in and display the contents. I
put it into a datagrid and also use a repeater (the former was a quick
way of seeing what happened, the latter was in an attempt to have more
flexibility over what I do with the data).

The grid shows the five items in the XML file, but the repeater only
shows three. If you look at the source generated, it seems that the
other two entries are blank.

Anyone any idea why? Any help appreciated.

First the ASP.NET file ...

<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="Syst em.Data" %>
<script runat="server">

void Page_Load(Objec t sender, EventArgs e) {
DataSet dstXML;

dstXML = new DataSet();
dstXML.ReadXml( MapPath("SiteMa p.xml"));
// display the info in a repeater
rptSiteMap.Data Source = dstXML;
rptSiteMap.Data Bind();
// display the info in a grid
dgrdData.DataSo urce = dstXML;
dgrdData.DataBi nd();
}

void rptSiteMap_Item (Object sender, RepeaterItemEve ntArgs e) {
if (e.Item.ItemTyp e == ListItemType.It em) {
Literal litLink = (Literal)e.Item .FindControl("l itLink");
litLink.Text = (string)DataBin der.Eval(e.Item .DataItem, "Title") + "
<small>(" + (string)DataBin der.Eval(e.Item .DataItem, "URL") +
")</small>";
}
}

</script>

<html>
<head>
<style type="text/css">
body, p, td, h1, h2, h3 {
font-family: Arial;
color: #0000ff;
background-color: #ffffff;
}
</style>
</head>

<body>
<form runat="server">
<p><asp:Repeate r id="rptSiteMap " OnItemDataBound ="rptSiteMap_It em"
Runat="Server">
<ItemTemplate>< br><asp:Literal id="litLink" Runat="Server"
/></ItemTemplate>
</asp:Repeater></p>

<hr><br>

<asp:DataGrid id="dgrdData" Runat="Server" />

</form>
</body>
</html>
Now the XML file ...

<SiteMap>
<Page>
<URL>/</URL>
<Title>Daisy Documentation Centre</Title>
<Description> A collection of useful and interesting links, pages, files
and stuff.</Description>
</Page>

<Page>
<URL>/DotNET/</URL>
<Title>My DotNet Tests</Title>
<Description> My tests of ASP.NET and other things.</Description>
</Page>

<Page>
<URL>/ReadXML.aspx</URL>
<Title>Read An XML File</Title>
<Description> My working out how to read an XML file from disk, how to
cache it and how to display the contents.</Description>
</Page>

<Page>
<URL>/links.asp</URL>
<Title>Useful Links</Title>
<Description>Li nks to places of interest outside of the
DDC.</Description>
</Page>

<Page>
<URL>/servervars.asp</URL>
<Title>IIS6 ASP Server Variables</Title>
<Description> A listing of the server variables held by IIS when running
ASP (Classic, not .NET).</Description>
</Page>

</SiteMap>

and finally the HTML sent to the browser (for clarity, I've only posted
the relevant bits and ignored the view state info, etc) ...

<p><br>Daisy Documentation Centre <small>(/)</small><br><br>R ead An XML
File <small>(/ReadXML.aspx)</small><br><br>I IS6 ASP Server Variables
<small>(/servervars.asp) </small></p>

<hr><br>

<table cellspacing="0" rules="all" border="1" id="dgrdData"
style="border-collapse:collap se;">
<tr>
<td>URL</td><td>Title</td><td>Descript ion</td>
</tr><tr>
<td>/</td><td>Daisy Documentation Centre</td><td>A
collection of useful and interesting links, pages, files and stuff.</td>
</tr><tr>
<td>/DotNET/</td><td>My DotNet Tests</td><td>My tests of
ASP.NET and other things.</td>
</tr><tr>
<td>/ReadXML.aspx</td><td>Read An XML File</td><td>My
working out how to read an XML file from disk, how to cache it and how
to display the contents.</td>
</tr><tr>
<td>/links.asp</td><td>Useful Links</td><td>Links to
places of interest outside of the DDC.</td>
</tr><tr>
<td>/servervars.asp</td><td>IIS6 ASP Server
Variables</td><td>A listing of the server variables held by IIS when
running ASP (Classic, not .NET).</td>
</tr>
</table>
--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
2 1509
Try changing this :

if (e.Item.ItemTyp e == ListItemType.It em)

to this :

if((e.Item.Item Type == ListItemType.It em) ||
(e.Item.ItemTyp e == ListItemType.Al ternatingItem))

See the test at : http://asp.net.do/test/readXML.aspx

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=============== ======

"Alan Silver" <al*********@no spam.thanx> wrote in message
news:6P******** ******@nospamth ankyou.spam...
Hello,

I am just trying out reading an XML file in an ASP.NET page, but am
having a little trouble. I'm sure this is something really obvious and
dumb, but I can't see what ...

I have an XML file that contains some site map info (see further down),
and I have written a page to read this in and display the contents. I
put it into a datagrid and also use a repeater (the former was a quick
way of seeing what happened, the latter was in an attempt to have more
flexibility over what I do with the data).

The grid shows the five items in the XML file, but the repeater only
shows three. If you look at the source generated, it seems that the
other two entries are blank.

Anyone any idea why? Any help appreciated.

First the ASP.NET file ...

<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="Syst em.Data" %>
<script runat="server">

void Page_Load(Objec t sender, EventArgs e) {
DataSet dstXML;

dstXML = new DataSet();
dstXML.ReadXml( MapPath("SiteMa p.xml"));
// display the info in a repeater
rptSiteMap.Data Source = dstXML;
rptSiteMap.Data Bind();
// display the info in a grid
dgrdData.DataSo urce = dstXML;
dgrdData.DataBi nd();
}

void rptSiteMap_Item (Object sender, RepeaterItemEve ntArgs e) {
if (e.Item.ItemTyp e == ListItemType.It em) {
Literal litLink = (Literal)e.Item .FindControl("l itLink");
litLink.Text = (string)DataBin der.Eval(e.Item .DataItem, "Title") + "
<small>(" + (string)DataBin der.Eval(e.Item .DataItem, "URL") +
")</small>";
}
}

</script>

<html>
<head>
<style type="text/css">
body, p, td, h1, h2, h3 {
font-family: Arial;
color: #0000ff;
background-color: #ffffff;
}
</style>
</head>

<body>
<form runat="server">
<p><asp:Repeate r id="rptSiteMap " OnItemDataBound ="rptSiteMap_It em"
Runat="Server">
<ItemTemplate>< br><asp:Literal id="litLink" Runat="Server"
/></ItemTemplate>
</asp:Repeater></p>

<hr><br>

<asp:DataGrid id="dgrdData" Runat="Server" />

</form>
</body>
</html>
Now the XML file ...

<SiteMap>
<Page>
<URL>/</URL>
<Title>Daisy Documentation Centre</Title>
<Description> A collection of useful and interesting links, pages, files
and stuff.</Description>
</Page>

<Page>
<URL>/DotNET/</URL>
<Title>My DotNet Tests</Title>
<Description> My tests of ASP.NET and other things.</Description>
</Page>

<Page>
<URL>/ReadXML.aspx</URL>
<Title>Read An XML File</Title>
<Description> My working out how to read an XML file from disk, how to
cache it and how to display the contents.</Description>
</Page>

<Page>
<URL>/links.asp</URL>
<Title>Useful Links</Title>
<Description>Li nks to places of interest outside of the
DDC.</Description>
</Page>

<Page>
<URL>/servervars.asp</URL>
<Title>IIS6 ASP Server Variables</Title>
<Description> A listing of the server variables held by IIS when running
ASP (Classic, not .NET).</Description>
</Page>

</SiteMap>

and finally the HTML sent to the browser (for clarity, I've only posted
the relevant bits and ignored the view state info, etc) ...

<p><br>Daisy Documentation Centre <small>(/)</small><br><br>R ead An XML
File <small>(/ReadXML.aspx)</small><br><br>I IS6 ASP Server Variables
<small>(/servervars.asp) </small></p>

<hr><br>

<table cellspacing="0" rules="all" border="1" id="dgrdData"
style="border-collapse:collap se;">
<tr>
<td>URL</td><td>Title</td><td>Descript ion</td>
</tr><tr>
<td>/</td><td>Daisy Documentation Centre</td><td>A
collection of useful and interesting links, pages, files and stuff.</td>
</tr><tr>
<td>/DotNET/</td><td>My DotNet Tests</td><td>My tests of
ASP.NET and other things.</td>
</tr><tr>
<td>/ReadXML.aspx</td><td>Read An XML File</td><td>My
working out how to read an XML file from disk, how to cache it and how
to display the contents.</td>
</tr><tr>
<td>/links.asp</td><td>Useful Links</td><td>Links to
places of interest outside of the DDC.</td>
</tr><tr>
<td>/servervars.asp</td><td>IIS6 ASP Server
Variables</td><td>A listing of the server variables held by IIS when
running ASP (Classic, not .NET).</td>
</tr>
</table>
--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #2
>Try changing this :

if (e.Item.ItemTyp e == ListItemType.It em)

to this :

if((e.Item.Item Type == ListItemType.It em) ||
(e.Item.ItemTyp e == ListItemType.Al ternatingItem))

See the test at : http://asp.net.do/test/readXML.aspx
Doh, obvious eh?

Actually I did know about the AlternatingItem bit, but assuming
(incorrectly as it turned out) that since I had only used the
ItemTemplate in the repeater, that every item called would use that and
not the non-existent AlternatingItem Template.

You live and learn eh? Thanks very much for the reply.
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
============== =======

"Alan Silver" <al*********@no spam.thanx> wrote in message
news:6P******* *******@nospamt hankyou.spam...
Hello,

I am just trying out reading an XML file in an ASP.NET page, but am
having a little trouble. I'm sure this is something really obvious and
dumb, but I can't see what ...

I have an XML file that contains some site map info (see further down),
and I have written a page to read this in and display the contents. I
put it into a datagrid and also use a repeater (the former was a quick
way of seeing what happened, the latter was in an attempt to have more
flexibility over what I do with the data).

The grid shows the five items in the XML file, but the repeater only
shows three. If you look at the source generated, it seems that the
other two entries are blank.

Anyone any idea why? Any help appreciated.

First the ASP.NET file ...

<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="Syst em.Data" %>
<script runat="server">

void Page_Load(Objec t sender, EventArgs e) {
DataSet dstXML;

dstXML = new DataSet();
dstXML.ReadXml( MapPath("SiteMa p.xml"));
// display the info in a repeater
rptSiteMap.Data Source = dstXML;
rptSiteMap.Data Bind();
// display the info in a grid
dgrdData.DataSo urce = dstXML;
dgrdData.DataBi nd();
}

void rptSiteMap_Item (Object sender, RepeaterItemEve ntArgs e) {
if (e.Item.ItemTyp e == ListItemType.It em) {
Literal litLink = (Literal)e.Item .FindControl("l itLink");
litLink.Text = (string)DataBin der.Eval(e.Item .DataItem, "Title") + "
<small>(" + (string)DataBin der.Eval(e.Item .DataItem, "URL") +
")</small>";
}
}

</script>

<html>
<head>
<style type="text/css">
body, p, td, h1, h2, h3 {
font-family: Arial;
color: #0000ff;
background-color: #ffffff;
}
</style>
</head>

<body>
<form runat="server">
<p><asp:Repeate r id="rptSiteMap " OnItemDataBound ="rptSiteMap_It em"
Runat="Server">
<ItemTemplate>< br><asp:Literal id="litLink" Runat="Server"
/></ItemTemplate>
</asp:Repeater></p>

<hr><br>

<asp:DataGrid id="dgrdData" Runat="Server" />

</form>
</body>
</html>
Now the XML file ...

<SiteMap>
<Page>
<URL>/</URL>
<Title>Daisy Documentation Centre</Title>
<Description> A collection of useful and interesting links, pages, files
and stuff.</Description>
</Page>

<Page>
<URL>/DotNET/</URL>
<Title>My DotNet Tests</Title>
<Description> My tests of ASP.NET and other things.</Description>
</Page>

<Page>
<URL>/ReadXML.aspx</URL>
<Title>Read An XML File</Title>
<Description> My working out how to read an XML file from disk, how to
cache it and how to display the contents.</Description>
</Page>

<Page>
<URL>/links.asp</URL>
<Title>Useful Links</Title>
<Description>Li nks to places of interest outside of the
DDC.</Description>
</Page>

<Page>
<URL>/servervars.asp</URL>
<Title>IIS6 ASP Server Variables</Title>
<Description> A listing of the server variables held by IIS when running
ASP (Classic, not .NET).</Description>
</Page>

</SiteMap>

and finally the HTML sent to the browser (for clarity, I've only posted
the relevant bits and ignored the view state info, etc) ...

<p><br>Daisy Documentation Centre <small>(/)</small><br><br>R ead An XML
File <small>(/ReadXML.aspx)</small><br><br>I IS6 ASP Server Variables
<small>(/servervars.asp) </small></p>

<hr><br>

<table cellspacing="0" rules="all" border="1" id="dgrdData"
style="border-collapse:collap se;">
<tr>
<td>URL</td><td>Title</td><td>Descript ion</td>
</tr><tr>
<td>/</td><td>Daisy Documentation Centre</td><td>A
collection of useful and interesting links, pages, files and stuff.</td>
</tr><tr>
<td>/DotNET/</td><td>My DotNet Tests</td><td>My tests of
ASP.NET and other things.</td>
</tr><tr>
<td>/ReadXML.aspx</td><td>Read An XML File</td><td>My
working out how to read an XML file from disk, how to cache it and how
to display the contents.</td>
</tr><tr>
<td>/links.asp</td><td>Useful Links</td><td>Links to
places of interest outside of the DDC.</td>
</tr><tr>
<td>/servervars.asp</td><td>IIS6 ASP Server
Variables</td><td>A listing of the server variables held by IIS when
running ASP (Classic, not .NET).</td>
</tr>
</table>
--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2674
by: Erik Neves | last post by:
I need help with utf-8 before i go bald and the rest of my hair turns white! Platform: Mac OS X 10.2.6 Safari 1.0 (v85) Internet Explorer:mac 5.2.3 (5815.1) Apache 2.0.47 PHP 4.3.2 (Apache 2 module) libiconv 1.8
44
3897
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with other browsers (I checked it under Konqueror). Thank you in advance for your help. Regards. /Mariusz <HTML>
2
391
by: James Coburn's Grey Helmet Hair | last post by:
When I try to compile my GTK# app, the compiler says: jbailo@linux:~/mono> mcs buttons.cs -r gtk-sharp.dll -r glib-sharp.dll -r -o buttons.exe error CS2001: Source file 'buttons.exe' could not be opened Compilation failed: 1 error(s), 0 warnings jbailo@linux:~/mono> mcs buttons.cs -r gtk-sharp.dll -r glib-sharp.dll -o buttons.exe buttons.cs(8) error CS0246: The namespace `System.Drawing' can not be found (missing assembly reference?)
21
66848
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what are the other approaches. please advise. thanks!!
149
25207
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
36
2115
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a property and 2 methods, along with a constructor (where you use New(), I think, yes?). So, I decided to create a class that represents a die, which can be rolled - using a Roll() method - and which has a property to find out the value on the face of...
0
1298
by: =?Utf-8?B?RWFjaHVz?= | last post by:
I've made several attempts to upgrade an application from asp.net 1.1 to 2.0. I open the web site by selecting the vbproj file, by selecting the solution file, or by selecting the web application. VS 2005 opens the conversion wizard, backs up the files, makes a brief show of shuffling bits around, and announces that the conversion is complete. If it produces a conversion report, the report either says that one file was converted (the vbproj...
8
3926
by: Radu | last post by:
Hi. I have an ASP control on my page: <asp:Calendar ID="calStart" ................ Etc </asp:Calendar> and I have a Custom Validator defined as <asp:CustomValidator
20
1573
by: cmrchs | last post by:
Hi, I have in my web application project (VS.NET 2008) : - a webform (webform2.aspx, webform2.aspx.cs, webform2.aspx.designer.cs) - a code-file Product.cs. But i can't use the definition of 'Product' nowhere in my page-class- file (webform2.aspx.cs)
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.