feedparser_rs/namespace/
mod.rs1pub mod cc;
30pub mod content;
32pub mod dublin_core;
34pub mod georss;
36pub mod media_rss;
38pub mod syndication;
40
41pub mod namespaces {
43 pub const DUBLIN_CORE: &str = "http://purl.org/dc/elements/1.1/";
45
46 pub const CONTENT: &str = "http://purl.org/rss/1.0/modules/content/";
48
49 pub const MEDIA: &str = "http://search.yahoo.com/mrss/";
51
52 pub const ATOM: &str = "http://www.w3.org/2005/Atom";
54
55 pub const RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
57
58 pub const RSS_10: &str = "http://purl.org/rss/1.0/";
60
61 pub const SYNDICATION: &str = "http://purl.org/rss/1.0/modules/syndication/";
63
64 pub const ITUNES: &str = "http://www.itunes.com/dtds/podcast-1.0.dtd";
66
67 pub const PODCAST: &str = "https://podcastindex.org/namespace/1.0";
69
70 pub const GEORSS: &str = "http://www.georss.org/georss";
72
73 pub const CC: &str = "http://creativecommons.org/ns#";
75
76 pub const CREATIVE_COMMONS: &str = "http://backend.userland.com/creativeCommonsRssModule";
78}
79
80pub fn get_namespace_uri(prefix: &str) -> Option<&'static str> {
90 match prefix {
91 "dc" => Some(namespaces::DUBLIN_CORE),
92 "content" => Some(namespaces::CONTENT),
93 "media" => Some(namespaces::MEDIA),
94 "atom" => Some(namespaces::ATOM),
95 "rdf" => Some(namespaces::RDF),
96 "syn" | "syndication" => Some(namespaces::SYNDICATION),
97 "itunes" => Some(namespaces::ITUNES),
98 "podcast" => Some(namespaces::PODCAST),
99 "georss" => Some(namespaces::GEORSS),
100 "cc" => Some(namespaces::CC),
101 "creativeCommons" => Some(namespaces::CREATIVE_COMMONS),
102 _ => None,
103 }
104}
105
106pub fn get_namespace_prefix(uri: &str) -> Option<&'static str> {
116 match uri {
117 namespaces::DUBLIN_CORE => Some("dc"),
118 namespaces::CONTENT => Some("content"),
119 namespaces::MEDIA => Some("media"),
120 namespaces::ATOM => Some("atom"),
121 namespaces::RDF => Some("rdf"),
122 namespaces::SYNDICATION => Some("syn"),
123 namespaces::ITUNES => Some("itunes"),
124 namespaces::PODCAST => Some("podcast"),
125 namespaces::GEORSS => Some("georss"),
126 namespaces::CC => Some("cc"),
127 namespaces::CREATIVE_COMMONS => Some("creativeCommons"),
128 _ => None,
129 }
130}
131
132#[cfg(test)]
133mod tests {
134 use super::*;
135
136 #[test]
137 fn test_get_namespace_uri() {
138 assert_eq!(
139 get_namespace_uri("dc"),
140 Some("http://purl.org/dc/elements/1.1/")
141 );
142 assert_eq!(
143 get_namespace_uri("content"),
144 Some("http://purl.org/rss/1.0/modules/content/")
145 );
146 assert_eq!(
147 get_namespace_uri("media"),
148 Some("http://search.yahoo.com/mrss/")
149 );
150 assert_eq!(get_namespace_uri("unknown"), None);
151 }
152
153 #[test]
154 fn test_get_namespace_prefix() {
155 assert_eq!(
156 get_namespace_prefix("http://purl.org/dc/elements/1.1/"),
157 Some("dc")
158 );
159 assert_eq!(
160 get_namespace_prefix("http://purl.org/rss/1.0/modules/content/"),
161 Some("content")
162 );
163 assert_eq!(
164 get_namespace_prefix("http://search.yahoo.com/mrss/"),
165 Some("media")
166 );
167 assert_eq!(get_namespace_prefix("http://unknown.example.com/"), None);
168 }
169}