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 CC: &str = "http://creativecommons.org/ns#";
81
82 pub const CREATIVE_COMMONS: &str = "http://backend.userland.com/creativeCommonsRssModule";
84
85 pub const THREADING: &str = "http://purl.org/syndication/thread/1.0";
87
88 pub const SLASH: &str = "http://purl.org/rss/1.0/modules/slash/";
90
91 pub const WFW: &str = "http://wellformedweb.org/CommentAPI/";
93}
94
95pub fn get_namespace_uri(prefix: &str) -> Option<&'static str> {
105 match prefix {
106 "dc" => Some(namespaces::DUBLIN_CORE),
107 "content" => Some(namespaces::CONTENT),
108 "media" => Some(namespaces::MEDIA),
109 "atom" => Some(namespaces::ATOM),
110 "rdf" => Some(namespaces::RDF),
111 "syn" | "syndication" => Some(namespaces::SYNDICATION),
112 "itunes" => Some(namespaces::ITUNES),
113 "podcast" => Some(namespaces::PODCAST),
114 "georss" => Some(namespaces::GEORSS),
115 "cc" => Some(namespaces::CC),
116 "creativeCommons" => Some(namespaces::CREATIVE_COMMONS),
117 "thr" => Some(namespaces::THREADING),
118 "slash" => Some(namespaces::SLASH),
119 "wfw" => Some(namespaces::WFW),
120 _ => None,
121 }
122}
123
124pub fn get_namespace_prefix(uri: &str) -> Option<&'static str> {
134 match uri {
135 namespaces::DUBLIN_CORE => Some("dc"),
136 namespaces::CONTENT => Some("content"),
137 namespaces::MEDIA => Some("media"),
138 namespaces::ATOM => Some("atom"),
139 namespaces::RDF => Some("rdf"),
140 namespaces::SYNDICATION => Some("syn"),
141 namespaces::ITUNES => Some("itunes"),
142 namespaces::PODCAST => Some("podcast"),
143 namespaces::GEORSS => Some("georss"),
144 namespaces::CC => Some("cc"),
145 namespaces::CREATIVE_COMMONS => Some("creativeCommons"),
146 namespaces::THREADING => Some("thr"),
147 namespaces::SLASH => Some("slash"),
148 namespaces::WFW => Some("wfw"),
149 _ => None,
150 }
151}
152
153#[cfg(test)]
154mod tests {
155 use super::*;
156
157 #[test]
158 fn test_get_namespace_uri() {
159 assert_eq!(
160 get_namespace_uri("dc"),
161 Some("http://purl.org/dc/elements/1.1/")
162 );
163 assert_eq!(
164 get_namespace_uri("content"),
165 Some("http://purl.org/rss/1.0/modules/content/")
166 );
167 assert_eq!(
168 get_namespace_uri("media"),
169 Some("http://search.yahoo.com/mrss/")
170 );
171 assert_eq!(get_namespace_uri("unknown"), None);
172 }
173
174 #[test]
175 fn test_get_namespace_prefix() {
176 assert_eq!(
177 get_namespace_prefix("http://purl.org/dc/elements/1.1/"),
178 Some("dc")
179 );
180 assert_eq!(
181 get_namespace_prefix("http://purl.org/rss/1.0/modules/content/"),
182 Some("content")
183 );
184 assert_eq!(
185 get_namespace_prefix("http://search.yahoo.com/mrss/"),
186 Some("media")
187 );
188 assert_eq!(get_namespace_prefix("http://unknown.example.com/"), None);
189 }
190}