pub struct WmlDocument {
pub file_name: String,
/* private fields */
}Expand description
A WordprocessingML document held as its package bytes plus the main
document part parsed on demand. Mirrors the C# WmlDocument
(DocumentByteArray + lazy MainDocumentPart) used by the
crate::comparer pipeline.
Constructed with Self::from_bytes (which admits under
InputLimits::compare);
reads and edits go through Self::dom / Self::dom_mut and
Self::part_fs / Self::part_fs_mut.
Fields§
§file_name: StringFileName — the inherited WmlDocument property, kept as a free
string for callers that gather metrics or build paths from it.
Implementations§
Source§impl WmlDocument
impl WmlDocument
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<WmlDocument, OpcError>
pub fn from_bytes(bytes: &[u8]) -> Result<WmlDocument, OpcError>
Opens bytes as a .docx, admits it under
InputLimits::compare,
and lazily parses the main document part on the first
Self::main_document call.
§Errors
OpcError::Iowrappingcrate::admission::AdmissionErrorwhen admission refuses the bytes (a budget, a duplicate or unsafe part name, an encrypted package, an.docor RTF that is not a.docx, or an XML part too deep or malformed).- Any error
PartFs::openreports (the standard OPC errors:OpcError::Zip,OpcError::PartNotFound, etc.).
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
The bytes the document was opened from. Edits through
Self::part_fs_mut or Self::dom_mut do not show here;
repack through crate::opc::PartFs::to_zip to get the new bytes.
Sourcepub fn main_document_part_name(&self) -> String
pub fn main_document_part_name(&self) -> String
The main document part name (word/document.xml unless OPC
relationships name otherwise). The string always returned even
when the part is absent.
Sourcepub fn main_document(&mut self) -> Result<NodeId, OpcError>
pub fn main_document(&mut self) -> Result<NodeId, OpcError>
Parses the main document part (once) and returns its document node. Subsequent calls return the cached node.
§Errors
OpcError::PartNotFound when the package has no part at
Self::main_document_part_name (the body the comparer would
diff into is missing).
Sourcepub fn main_document_root(&mut self) -> Result<NodeId, OpcError>
pub fn main_document_root(&mut self) -> Result<NodeId, OpcError>
The root element (<w:document>) of the main document part.
§Errors
OpcError::PartNotFound when the part is absent, or the parsed
XML has no root element.
Sourcepub fn dom(&self) -> &Dom
pub fn dom(&self) -> &Dom
The arena DOM (read-only). Empty until a successful
Self::main_document parses the part into it.
Sourcepub fn dom_mut(&mut self) -> &mut Dom
pub fn dom_mut(&mut self) -> &mut Dom
The arena DOM (mutable). The comparer mutates this DOM while it produces the body diff.
Sourcepub fn part_fs(&self) -> &PartFs
pub fn part_fs(&self) -> &PartFs
The opened OPC package (read-only), by which every other part and relationship is read.
Sourcepub fn part_fs_mut(&mut self) -> &mut PartFs
pub fn part_fs_mut(&mut self) -> &mut PartFs
The opened OPC package (mutable).