468,321 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Hyperlink asp control doesn't appear when set

Hi, I've got an XML file with one <title> and one <link> attribute.
What I want to do is implement a hyperlink with the name of the <title> element and whose NavigateUrl property is set to the <link> element.

For an unusual reason, the hyperlink never appears but, when debugged, both items from the XML file are appended to the hyperlink. What have I done wrong?


Expand|Select|Wrap|Line Numbers
  1. private void ReadXML()
  2.     {
  3.         using (StreamReader sr = File.OpenText(xmlFile))
  4.         {
  5.             while (!sr.EndOfStream && sr.Read() > 0)
  6.             {
  7.                 string line = sr.ReadLine();
  8.                 if (line.Contains("<title>"))
  9.                 {
  10.                     // read until we reach </title>
  11.                     HyperLink4.Text = line.Replace("<title>", ""); // read until <title>
  12.                     HyperLink4.Text = line.Replace("</title>", ""); // read until <title>
  13.                 }
  14.                 // link should follow straight after
  15.                 else if (line.Contains("<link>"))
  16.                 {
  17.                     HyperLink4.NavigateUrl = line.Replace("<link>", "");
  18.                     HyperLink4.NavigateUrl = line.Replace("</link>", ""); // read until <title>
  19.                 }
  20.             }
  21.         }
  22.     }
Mar 20 '10 #1
4 2349
2,057 Expert 2GB
Could you post your input and expected output?
It looks like you have something like
Which ends up being:

Did you want your output in html link form, eg
<a href="http://www.google.ca">Search</a>
or some other different form?
Mar 22 '10 #2
Sure, my input is:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel>
<title>BBC News | UK | UK Edition</title>

<title>Clegg bids to cool coalition talk</title>
<description>Nick Clegg is to say he is "not the kingmaker" amid speculation about the Lib Dems' possible role in a coalition government.

An I expect my output to be:

BBC News | UK | UK Edition


Clegg bids to cool coalition talk

Nick Clegg is to say he is "not the kingmaker" amid speculation about the Lib Dems' possible role in a coalition government.


I guess HTML form would be more flexible than an asp:Hyperlink object but it doesn't really matter, I just want to turn the titles within the file into hyperlinks which the user can use to go directly to the report
Mar 22 '10 #3
2,057 Expert 2GB
Ah, I see, the problem is that you're overwriting it. eg, you'd get

Text = "BBC News | UK | UK Edition</title>" with <title> removed, then
Text = "<title>BBC News | UK | UK Edition" with </title> removed.

Expand|Select|Wrap|Line Numbers
  1. string line = sr.ReadLine(); 
  2. int i = line.IndexOf("<title>");
  3. int j = line.IndexOf("</title>");
  5. // If you have a multi-line title, this won't deal with it.
  6. if(i != -1 && j != -1)
  7. {
  8.   HyperLink4.Text = line.Substring(i, j-i);
  9. }
and do the same thing with link.

You are assuming each element only comes on one line each, correct?
Mar 22 '10 #4
It's OK, I've solved this by using a better a approach - using Repeaters, Literals and Hyperlinks.

For the benefit of newbies to rss, just like me, this is the site I used:

Mar 24 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Andreas Meffert | last post: by
9 posts views Thread by Leigh Kendall | last post: by
1 post views Thread by Pat | last post: by
reply views Thread by Kevin Quigley | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
20 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.