JFLib

diagram_core/src/formula/xml.rs#

Source: lib/diagram_core/src/formula/xml.rs

xml -- a small element tree of a theme part (DrawingML with Visio's extensions)

Theme parts are a few dozen kilobytes of attributes; the engine reads colours, fonts and
style lists from them.  The reading is formats::xml::Lenient's (nothing is an error: a broken
tag or reference is read as far as it goes); this tree keeps elements (local names, attributes
without the xmlns declarations, children) and drops text, comments, processing instructions and
the DOCTYPE; an end tag closes the element open last.  Limits: 200 000 elements, depth 256; a
second root element or a limit ends the tree there.
  • struct Elem one element: its local name (prefix removed), attributes (local names) and children

    • name: String -- the name without prefix
    • attrs: Vec<(String, String)> -- the attributes without prefixes, values with entities decoded
    • children: Vec<u32> -- the children (indices into Tree::elems)
  • struct Tree a parsed part

    • elems: Vec<Elem> -- all elements; 0 is the root when the part had one

impl Tree

  • fn parse(data: &[u8]) -> Tree read a part (UTF-8; a BOM is skipped)
  • fn get(&self, i: u32) -> Option<&Elem> an element
  • fn child(&self, i: u32, name: &str) -> Option<u32> the first child of i named name
  • fn children<'a>(&'a self, i: u32, name: &'a str) -> impl Iterator<Item = u32> + 'a the children of i named name
  • fn path(&self, i: u32, names: &[&str]) -> Option<u32> the element at a path of names below i (each step the first match)
  • fn find(&self, i: u32, name: &str) -> Option<u32> the first element named name anywhere below i (depth first)
  • fn attr(&self, i: u32, name: &str) -> Option<&str> an attribute of i

Source: docs/API.md in the JFLib repository.