pub struct Document {
pub package: Package,
pub content: Element,
pub styles_part: Option<Element>,
pub styles: Styles,
pub meta: Meta,
}Expand description
A document read from a package: everything the three formats share.
Fields§
§package: PackageThe package itself, which keeps every entry whether or not it was read here, so that writing gives back a document and not a subset of one.
content: ElementThe parsed content.xml.
styles_part: Option<Element>The parsed styles.xml, if the package has one.
styles: StylesEvery style in the document, from both parts.
meta: MetaWhat the document says about itself.
Implementations§
Source§impl Document
impl Document
Sourcepub fn read(
bytes: &[u8],
wanted: &'static [&'static str],
) -> Result<Self, Error>
pub fn read( bytes: &[u8], wanted: &'static [&'static str], ) -> Result<Self, Error>
Read a package and check its media type.
§Errors
The bytes are not a package, the package declares a different media type,
or content.xml is absent or not well formed.
Sourcepub fn body(&self) -> Option<&Element>
pub fn body(&self) -> Option<&Element>
The office:body element, which every format has exactly one of.
Sourcepub fn body_of(&self, local: &str) -> Option<&Element>
pub fn body_of(&self, local: &str) -> Option<&Element>
The part of the body this format keeps its content in: office:text,
office:spreadsheet or office:presentation.
Sourcepub fn body_path(&self, local: &str) -> Option<Vec<usize>>
pub fn body_path(&self, local: &str) -> Option<Vec<usize>>
Where Self::body_of is under the content root, as a path of child
indices: what an editor addresses the body’s paragraphs from.
Sourcepub fn name(&self, ns: &Ns, local: &str) -> Name
pub fn name(&self, ns: &Ns, local: &str) -> Name
A name for writing into the document, in the prefix the document declares for the namespace on its content root, or the conventional one where it declares none.
Sourcepub fn declares(&self, ns: &Ns) -> bool
pub fn declares(&self, ns: &Ns) -> bool
Whether the content root declares a namespace, which is what decides whether an attribute in it may be written at all.
Sourcepub fn version(&self) -> Option<&str>
pub fn version(&self) -> Option<&str>
The version of the format the document declares, as office:version.
Sourcepub fn picture(&self, href: &str) -> Option<&[u8]>
pub fn picture(&self, href: &str) -> Option<&[u8]>
The bytes of a picture, by the xlink:href that referred to it.
A href that names an entry of the package gives those bytes. A href that
is a URL to somewhere else gives None: reaching it would be a network
request, which nothing in this suite makes.
Sourcepub fn write(&mut self) -> Result<Vec<u8>, Error>
pub fn write(&mut self) -> Result<Vec<u8>, Error>
Write the document back out, with the parsed parts re-serialized over the ones they were read from.
§Errors
The package could not be assembled.
Sourcepub fn write_verified(&mut self) -> Result<Vec<u8>, Error>
pub fn write_verified(&mut self) -> Result<Vec<u8>, Error>
Write the document and prove the bytes read back as the tree they were written from, which is what a save has to know before it touches the file.
The round-trip tests make the same claim over the corpus, and a person’s document is not in the corpus. One re-parse per save is the price, and the alternative is an editor that finds out it damaged a document after it has.
§Errors
The package could not be assembled, or a part came back different, in which case nothing should be written.