feedparser_rs/namespace/
mod.rs1pub mod cc;
32pub mod content;
34pub mod dublin_core;
36pub mod georss;
38pub mod media_rss;
40pub mod slash;
42pub mod syndication;
44pub mod threading;
46
47pub mod namespaces {
49 pub const DUBLIN_CORE: &str = "http://purl.org/dc/elements/1.1/";
51
52 pub const CONTENT: &str = "http://purl.org/rss/1.0/modules/content/";
54
55 pub const MEDIA: &str = "http://search.yahoo.com/mrss/";
57
58 pub const ATOM: &str = "http://www.w3.org/2005/Atom";
60
61 pub const RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
63
64 pub const RSS_10: &str = "http://purl.org/rss/1.0/";
66
67 pub const SYNDICATION: &str = "http://purl.org/rss/1.0/modules/syndication/";
69
70 pub const ITUNES: &str = "http://www.itunes.com/dtds/podcast-1.0.dtd";
72
73 pub const PODCAST: &str = "https://podcastindex.org/namespace/1.0";
75
76 pub const GEORSS: &str = "http://www.georss.org/georss";
78
79 pub const GEO: &str = "http://www.w3.org/2003/01/geo/wgs84_pos#";
81
82 pub const CC: &str = "http://creativecommons.org/ns#";
84
85 pub const CREATIVE_COMMONS: &str = "http://backend.userland.com/creativeCommonsRssModule";
87
88 pub const THREADING: &str = "http://purl.org/syndication/thread/1.0";
90
91 pub const SLASH: &str = "http://purl.org/rss/1.0/modules/slash/";
93
94 pub const WFW: &str = "http://wellformedweb.org/CommentAPI/";
96}
97
98pub fn get_namespace_uri(prefix: &str) -> Option<&'static str> {
108 match prefix {
109 "dc" => Some(namespaces::DUBLIN_CORE),
110 "content" => Some(namespaces::CONTENT),
111 "media" => Some(namespaces::MEDIA),
112 "atom" => Some(namespaces::ATOM),
113 "rdf" => Some(namespaces::RDF),
114 "syn" | "syndication" => Some(namespaces::SYNDICATION),
115 "itunes" => Some(namespaces::ITUNES),
116 "podcast" => Some(namespaces::PODCAST),
117 "georss" => Some(namespaces::GEORSS),
118 "geo" => Some(namespaces::GEO),
119 "cc" => Some(namespaces::CC),
120 "creativeCommons" => Some(namespaces::CREATIVE_COMMONS),
121 "thr" => Some(namespaces::THREADING),
122 "slash" => Some(namespaces::SLASH),
123 "wfw" => Some(namespaces::WFW),
124 _ => None,
125 }
126}
127
128pub fn get_namespace_prefix(uri: &str) -> Option<&'static str> {
138 match uri {
139 namespaces::DUBLIN_CORE => Some("dc"),
140 namespaces::CONTENT => Some("content"),
141 namespaces::MEDIA => Some("media"),
142 namespaces::ATOM => Some("atom"),
143 namespaces::RDF => Some("rdf"),
144 namespaces::SYNDICATION => Some("syn"),
145 namespaces::ITUNES => Some("itunes"),
146 namespaces::PODCAST => Some("podcast"),
147 namespaces::GEORSS => Some("georss"),
148 namespaces::GEO => Some("geo"),
149 namespaces::CC => Some("cc"),
150 namespaces::CREATIVE_COMMONS => Some("creativeCommons"),
151 namespaces::THREADING => Some("thr"),
152 namespaces::SLASH => Some("slash"),
153 namespaces::WFW => Some("wfw"),
154 _ => None,
155 }
156}
157
158#[cfg(test)]
159mod tests {
160 use super::*;
161
162 #[test]
163 fn test_get_namespace_uri() {
164 assert_eq!(
165 get_namespace_uri("dc"),
166 Some("http://purl.org/dc/elements/1.1/")
167 );
168 assert_eq!(
169 get_namespace_uri("content"),
170 Some("http://purl.org/rss/1.0/modules/content/")
171 );
172 assert_eq!(
173 get_namespace_uri("media"),
174 Some("http://search.yahoo.com/mrss/")
175 );
176 assert_eq!(get_namespace_uri("unknown"), None);
177 }
178
179 #[test]
180 fn test_get_namespace_prefix() {
181 assert_eq!(
182 get_namespace_prefix("http://purl.org/dc/elements/1.1/"),
183 Some("dc")
184 );
185 assert_eq!(
186 get_namespace_prefix("http://purl.org/rss/1.0/modules/content/"),
187 Some("content")
188 );
189 assert_eq!(
190 get_namespace_prefix("http://search.yahoo.com/mrss/"),
191 Some("media")
192 );
193 assert_eq!(get_namespace_prefix("http://unknown.example.com/"), None);
194 }
195}