By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

C# RSS feed generator & building the guid element

P: 2
Windows XP Pro
VS 2005 & C# (I'm fairly new to C# but have doing VB.Net going on 2yrs and VB6 for 5yrs.)

I'm using C# to build a custom RSS generator. I'm having trouble building the guid element for each item node in my feed. Some items do not have the "link" node because the description element is the content. So using the "link" as the guid will not work in my case, as some sites suggest and as feedvalidator.org complains when I do not have one. Plus the content may change so I'm attempting to set the isPermaLink attribute to false to instruct the RSS readers/subscribers not to use this field; it's just there for uniqueness.

Here is what I need:
<guid isPermaLink="false">69DA.....383D26EAF0</guid>

I have tried building a "guid" object but when its serialized it takes each property and makes them attributes of the guid element. Like this:
<guid guid="69DA......383D26EAF0" isPermaLink="false" />
Which is represented by the code snippet below.
Here's my "guid" element:
Expand|Select|Wrap|Line Numbers
  1. [XmlElement("guid")]
  2. public guidAttributes Guid
  3.  get    { return _guid;     }
  4.  set    { _guid = value; }
  5. }
  6.  
Here is my guidAttributes class:
Expand|Select|Wrap|Line Numbers
  1. public class guidAttributes
  2. {
  3.  private string _guid;
  4.  private bool _isPermaLink;
  5.  
  6.  [XmlAttribute("guid")]
  7.  public string Guid
  8.  {
  9.   get {  return _guid; }
  10.   set { _guid = value; }
  11.  }
  12.  
  13.  [XmlAttribute("isPermaLink")]
  14.  public bool isPermaLink
  15.  {
  16.   get {  return _isPermaLink; }
  17.   set { _isPermaLink = value; }
  18.  }
  19. }
  20.  
Changing the "guid" property above from Attribute to element like this:
Expand|Select|Wrap|Line Numbers
  1. [XmlElement("guid")]
  2.  public string Guid
  3.  
Produces this output:
<guid isPermaLink="false">
<guid>69DA.....383D26EAF0</guid>
</guid>

I'm close but not there and just need a bit of help to put all the pieces together.

Any help is greatly appreciated.

Thanks,

Michael
Nov 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: 2
Well a co-worker helped me out. Pretty simple in retrospect. I would post the code but everyone else must know how to do it or have no need for the implementation. If you do need to see the code, let me know.

Mike
Nov 16 '06 #2

Post your reply

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