diff options
Diffstat (limited to 'src/element.rs')
| -rw-r--r-- | src/element.rs | 44 | 
1 files changed, 36 insertions, 8 deletions
| diff --git a/src/element.rs b/src/element.rs index 35d73a3..0e0b8f1 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,23 +1,32 @@  // elements resemble a final tree, including inherited namespace information -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; + +use crate::{ +    error::Error, +    xml::{self, Attribute}, +};  // when are namespaces names chosen then if they are automatically calculated  // namespaces are held by readers and writers. +#[derive(PartialEq, Eq, Hash, Clone)]  pub struct Namespace { -    prefix: Option<String>, -    namespace: String, +    pub prefix: Option<String>, +    pub namespace: String,  }  // names are qualified, they contain a reference to the namespace (held within the reader/writer) +#[derive(PartialEq, Eq, Hash, Clone)]  pub struct Name { -    namespace: String, -    name: String, +    pub namespace: Namespace, +    pub name: String,  } -pub enum Node { +pub enum Content {      Element(Element),      Text(String), +    PI(String), +    Comment(String),  }  // should this be a trait? @@ -29,16 +38,35 @@ pub struct Element {      // namespace: String,      // hashmap of explicit namespace declarations on the element itself only      // possibly not needed as can be calculated at write time depending on context and qualified namespace, and for reading, element validity and namespaces are kept track of by the reader. -    pub namespace_decl: HashMap<Option<String>, String>, +    pub namespace_decl: HashSet<Namespace>,      // attributes can be in a different namespace than the element. how to make sure they are valid?      // maybe include the namespace instead of or with the prefix      // you can calculate the prefix from the namespaced name and the current writer context      // you can validate the prefix and calculate the namespace from the current reader context      // this results in readers and writers being able to return qualification errors as they aren't able to create elements until every part is qualified.      pub attributes: HashMap<Name, String>, -    pub children: Option<Vec<Node>>, +    pub content: Vec<Content>,  } +// impl<'s> TryFrom<xml::Element<'s>> for Element<'s> { +//     type Error = Error; + +//     fn try_from(xml_element: xml::Element) -> Result<Self, Self::Error> { +//         match &xml_element { +//             xml::Element::Empty(empty_elem_tag) => { +//                 let namespace_decl; +//                 let attributes; +//                 empty_elem_tag +//                     .attributes +//                     .into_iter() +//                     .filter(|attribute| matches!(attribute, Attribute::NamespaceDeclaration(_))); +//                 todo!() +//             } +//             xml::Element::NotEmpty(stag, content, etag) => todo!(), +//         } +//     } +// } +  // example of deriving an element:  // #[derive(XMLWrite, XMLRead)] | 
