hxml/node/
prolog.rs

1#[derive(Clone)]
2pub struct Prolog {
3    xml_decl: Option<XMLDecl>,
4    doctype_decl: Option<DocTypeDecl>
5}
6
7impl Prolog {
8
9    pub fn new(xml_decl: Option<XMLDecl>, doctype_decl: Option<DocTypeDecl>) -> Self {
10        Prolog { xml_decl, doctype_decl }
11    }
12
13    pub fn get_doctype_name(&self) -> Option<String> {
14
15        match &self.doctype_decl {
16            Some(d) => Some(d.name.clone()),
17            _ => None
18        }
19
20    }
21
22    pub fn get_xml_version(&self) -> Option<String> {
23
24        match &self.xml_decl {
25            Some(d) => Some(d.version_num.clone()),
26            _ => None
27        }
28
29    }
30
31    pub fn to_string(&self) -> String {
32        let xml_decl_string = match &self.xml_decl {
33            Some(x) => x.to_string(),
34            _ => String::new()
35        };
36        let doctype_decl_string = match &self.doctype_decl {
37            Some(d) => d.to_string(),
38            _ => String::new()
39        };
40
41        format!(
42            "{}{}",
43            xml_decl_string,
44            doctype_decl_string,
45        )
46    }
47
48}
49
50#[derive(Clone)]
51pub struct XMLDecl {
52    pub version_num: String
53}
54
55impl XMLDecl {
56
57    pub fn to_string(&self) -> String {
58        format!("<?xml version='{}'>", self.version_num)
59    }
60
61}
62
63#[derive(Clone)]
64pub struct DocTypeDecl {
65    pub name: String
66}
67
68impl DocTypeDecl {
69
70    pub fn new(name: String) -> DocTypeDecl {
71        DocTypeDecl { name }
72    }
73
74    pub fn to_string(&self) -> String {
75        format!("<!DOCTYPE {}>", self.name)
76    }
77
78}