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