Skip to content

Commit 3253b58

Browse files
committed
Update README.md to reflect changes in RssDocument usage and structure
1 parent c75dc77 commit 3253b58

File tree

1 file changed

+92
-84
lines changed

1 file changed

+92
-84
lines changed

README.md

Lines changed: 92 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,97 +17,105 @@ This version contain some important breaking changes:
1717
* `RssDocument` and all other entities converted from `class` to `record`.
1818

1919
## Usage example
20-
To read foreign rss feed you need to get stream with rss data and call `RssDocument.Load`
20+
To read a foreign RSS feed you need to get a stream with RSS data and deserialize it using `RssDocumentSerializer`.
21+
2122
```csharp
23+
using System.IO;
24+
using System.Text;
25+
26+
// read RSS XML from a stream and deserialize
27+
using var reader = new StreamReader(stream, Encoding.UTF8);
28+
var xml = reader.ReadToEnd();
29+
var serializer = new RssDocumentSerializer();
30+
RssDocument? rss = serializer.Deserialize(xml);
2231

23-
var request = WebRequest.Create("http://example.org/rss/");
24-
var response = request.GetResponse();
25-
var stream = response.GetResponseStream();
26-
Rss rss = RssDocument.Load(stream);
27-
28-
Assert.AreEqual("Example", rss.Channel.Title);
32+
Assert.AreEqual("Example", rss?.Channel.Title);
33+
```
34+
35+
To serialize a `RssDocument` back to XML:
36+
37+
```csharp
38+
var serializer = new RssDocumentSerializer();
39+
string xml = serializer.Serialize(rssDocument);
2940
```
3041

3142
### RSS object creating example
3243

33-
Complete rss object will look like this:
44+
Complete RSS object will look like this (updated to match current types and constructors):
45+
3446
```csharp
47+
using System.Collections.Generic;
48+
using System.Globalization;
3549

36-
return new RssDocument
50+
return new RssDocument
51+
{
52+
Channel = new RssChannel
53+
{
54+
// RssLink has a constructor that accepts a string URL
55+
AtomLink = new RssLink("http://atomlink.com") { Rel = Rel.self, Type = "text/plain" },
56+
Category = "category",
57+
Cloud = new RssCloud
58+
{
59+
Domain = "domain",
60+
Path = "path",
61+
Port = 1234,
62+
Protocol = Protocol.xmlrpc,
63+
RegisterProcedure = "registerProcedure"
64+
},
65+
Copyright = "copyrignt (c)",
66+
Description = "long description",
67+
Image = new RssImage
68+
{
69+
Description = "Image Description",
70+
Height = 100,
71+
Width = 100,
72+
Link = new RssUrl("http://image.link.url.com"),
73+
Title = "title",
74+
Url = new RssUrl("http://image.url.com")
75+
},
76+
Language = new CultureInfo("en").Name,
77+
LastBuildDate = new DateTime(2011, 7, 17, 15, 55, 41),
78+
Link = new RssUrl("http://channel.url.com"),
79+
ManagingEditor = "[email protected] (manager)",
80+
PubDate = new DateTime(2011, 7, 17, 15, 55, 41),
81+
Rating = "rating",
82+
SkipDays = new List<Day> { Day.Thursday, Day.Wednesday },
83+
SkipHours = new List<Hour> { new Hour(22), new Hour(15), new Hour(4) },
84+
TextInput = new RssTextInput
85+
{
86+
Description = "text input desctiption",
87+
Link = new RssUrl("http://text.input.link.com"),
88+
Name = "text input name",
89+
Title = "text input title"
90+
},
91+
Title = "channel title",
92+
TTL = 10,
93+
WebMaster = "[email protected] (webmaster)",
94+
Items = new List<RssItem>
95+
{
96+
new RssItem
3797
{
38-
Channel =
39-
new RssChannel
40-
{
41-
AtomLink = new RssLink { Href = new RssUrl("http://atomlink.com"), Rel = Rel.self, Type = "text/plain" },
42-
Category = "category",
43-
Cloud =
44-
new RssCloud
45-
{
46-
Domain = "domain",
47-
Path = "path",
48-
Port = 1234,
49-
Protocol = Protocol.xmlrpc,
50-
RegisterProcedure = "registerProcedure"
51-
},
52-
Copyright = "copyrignt (c)",
53-
Description = "long description",
54-
Image =
55-
new RssImage
56-
{
57-
Description = "Image Description",
58-
Height = 100,
59-
Width = 100,
60-
Link = new RssUrl("http://image.link.url.com"),
61-
Title = "title",
62-
Url = new RssUrl("http://image.url.com")
63-
},
64-
Language = new CultureInfo("en"),
65-
LastBuildDate = new DateTime(2011, 7, 17, 15, 55, 41),
66-
Link = new RssUrl("http://channel.url.com"),
67-
ManagingEditor = new RssEmail("[email protected] (manager)"),
68-
PubDate = new DateTime(2011, 7, 17, 15, 55, 41),
69-
Rating = "rating",
70-
SkipDays = new List<Day> { Day.Thursday, Day.Wednesday },
71-
SkipHours = new List<Hour> { new Hour(22), new Hour(15), new Hour(4) },
72-
TextInput =
73-
new RssTextInput
74-
{
75-
Description = "text input desctiption",
76-
Link = new RssUrl("http://text.input.link.com"),
77-
Name = "text input name",
78-
Title = "text input title"
79-
},
80-
Title = "channel title",
81-
TTL = 10,
82-
WebMaster = new RssEmail("[email protected] (webmaster)"),
83-
Items =
84-
new List<RssItem>
85-
{
86-
new RssItem
87-
{
88-
Author = new RssEmail("[email protected] (author)"),
89-
Category =
90-
new RssCategory
91-
{
92-
Domain = "category domain value",
93-
Text = "category text value"
94-
},
95-
Comments = new RssUrl("http://rss.item.comment.url.com"),
96-
Description = "item description",
97-
Enclosure =
98-
new RssEnclosure
99-
{
100-
Length = 1234,
101-
Type = "text/plain",
102-
Url = new RssUrl("http://rss.item.enclosure.type.url.com")
103-
},
104-
Link = new RssUrl("http://rss.item.link.url.com"),
105-
PubDate = new DateTime(2011, 7, 17, 15, 55, 41),
106-
Title = "item title",
107-
Guid = new RssGuid { IsPermaLink = false, Value = "guid value" },
108-
Source = new RssSource { Url = new RssUrl("http://rss.item.source.url.com") }
109-
}
110-
}
111-
}
112-
};
98+
Author = "[email protected] (author)",
99+
Category = new RssCategory
100+
{
101+
Domain = "category domain value",
102+
Text = "category text value"
103+
},
104+
Comments = new RssUrl("http://rss.item.comment.url.com"),
105+
Description = "item description",
106+
Enclosure = new RssEnclosure
107+
{
108+
Length = 1234,
109+
Type = "text/plain",
110+
Url = new RssUrl("http://rss.item.enclosure.type.url.com")
111+
},
112+
Link = new RssUrl("http://rss.item.link.url.com"),
113+
PubDate = new DateTime(2011, 7, 17, 15, 55, 41),
114+
Title = "item title",
115+
Guid = new RssGuid { IsPermaLink = false, Value = "guid value" },
116+
Source = new RssSource { Url = new RssUrl("http://rss.item.source.url.com") }
117+
}
118+
}
119+
}
120+
};
113121
```

0 commit comments

Comments
 (0)