pub struct XmlDoc {
pub version: String,
pub encoding: Option<String>,
pub standalone: Option<bool>,
pub dtd: Option<XmlDtd>,
pub undeclared_entity_refs: Vec<String>,
pub namespace_errors: Vec<String>,
pub warnings: Vec<String>,
pub reference_text: HashSet<NodeId>,
pub elements_with_entity_refs: HashSet<NodeId>,
/* private fields */
}Expand description
libxml2 xmlDoc.
Fields§
§version: StringXML version string; default "1.0".
encoding: Option<String>Encoding name from the XML declaration, if any.
standalone: Option<bool>Some(true/false) from standalone, None if omitted.
dtd: Option<XmlDtd>Internal / attached DTD, if any.
undeclared_entity_refs: Vec<String>Entity references the parse could not resolve. They are kept as written rather than being fatal when the subset is incomplete, and the validator reports them.
namespace_errors: Vec<String>Text nodes whose content came from a character or entity reference.
Such text is never ignorable whitespace: <foo><foo/> <foo/></foo>
against an element-only content model is character data where none is
allowed, and looking only at whether the text is blank cannot tell it
from the indentation beside it.
Namespace errors reported while parsing.
A namespace violation is never a well-formedness error: libxml2 parses the document and logs one, and its own conformance harness scores the namespace tests by looking for exactly that – the document must parse AND an error must have been reported. Rejecting instead would refuse input C reads, so they are recorded here for the caller to inspect.
warnings: Vec<String>Non-fatal problems worth telling the caller about – currently a declared encoding that contradicts the byte-order mark. The SAX error channel carries these too, but the default handler discards them, so a tree-parsing caller had no way to learn of one.
reference_text: HashSet<NodeId>§elements_with_entity_refs: HashSet<NodeId>Elements whose content included an entity reference, including one that
expanded to nothing. <foo>∅</foo> against EMPTY is content, and
the tree has no node to show for it.
Implementations§
Source§impl XmlDoc
impl XmlDoc
Sourcepub fn xml_new_doc(version: Option<&str>) -> Self
pub fn xml_new_doc(version: Option<&str>) -> Self
xmlNewDoc.
Sourcepub fn with_node_capacity(version: Option<&str>, cap: usize) -> Self
pub fn with_node_capacity(version: Option<&str>, cap: usize) -> Self
Build a document whose node arena is sized up front. Starting a parse used to allocate the arena, push into it, then reallocate on reserve – three trips for what one sized allocation does. The document node’s name is implied by its kind, so it stores no String either.
Sourcepub fn reserve_nodes(&mut self, n: usize)
pub fn reserve_nodes(&mut self, n: usize)
Pre-size the node arena. XML runs about one node per 10-15 input bytes, so a parser that knows the document length can skip most of the arena’s doubling-and-copy. Capped so a huge document cannot reserve wildly.
pub fn node(&self, id: NodeId) -> &Node
pub fn node_mut(&mut self, id: NodeId) -> &mut Node
pub fn kind(&self, id: NodeId) -> NodeKind
pub fn name(&self, id: NodeId) -> &str
pub fn prefix(&self, id: NodeId) -> Option<&str>
pub fn ns_uri(&self, id: NodeId) -> Option<&str>
pub fn content(&self, id: NodeId) -> &str
pub fn parent(&self, id: NodeId) -> Option<NodeId>
pub fn first_child(&self, id: NodeId) -> Option<NodeId>
pub fn last_child(&self, id: NodeId) -> Option<NodeId>
pub fn next_sibling(&self, id: NodeId) -> Option<NodeId>
pub fn prev_sibling(&self, id: NodeId) -> Option<NodeId>
pub fn first_attr(&self, id: NodeId) -> Option<NodeId>
pub fn ns_defs(&self, id: NodeId) -> &[(Option<String>, String)]
Sourcepub fn alloc_unnamed(&mut self, kind: NodeKind) -> NodeId
pub fn alloc_unnamed(&mut self, kind: NodeKind) -> NodeId
Allocate a node whose name is implied by its kind, storing no String.
XmlDoc::name reports the canonical name for these.
pub fn alloc(&mut self, kind: NodeKind, name: impl Into<String>) -> NodeId
Sourcepub fn xml_doc_get_root_element(&self) -> Option<NodeId>
pub fn xml_doc_get_root_element(&self) -> Option<NodeId>
xmlDocGetRootElement.
Sourcepub fn xml_doc_set_root_element(&mut self, elem: NodeId) -> Option<NodeId>
pub fn xml_doc_set_root_element(&mut self, elem: NodeId) -> Option<NodeId>
xmlDocSetRootElement. Returns the previous root, if any.
Sourcepub fn xml_new_doc_node(
&mut self,
ns_uri: Option<&str>,
name: &str,
content: Option<&str>,
) -> NodeId
pub fn xml_new_doc_node( &mut self, ns_uri: Option<&str>, name: &str, content: Option<&str>, ) -> NodeId
xmlNewDocNode.
Sourcepub fn xml_new_child(
&mut self,
parent: NodeId,
ns_uri: Option<&str>,
name: &str,
content: Option<&str>,
) -> NodeId
pub fn xml_new_child( &mut self, parent: NodeId, ns_uri: Option<&str>, name: &str, content: Option<&str>, ) -> NodeId
xmlNewChild.
Sourcepub fn xml_add_child(&mut self, parent: NodeId, child: NodeId)
pub fn xml_add_child(&mut self, parent: NodeId, child: NodeId)
xmlAddChild.
Sourcepub fn xml_add_next_sibling(&mut self, cur: NodeId, elem: NodeId)
pub fn xml_add_next_sibling(&mut self, cur: NodeId, elem: NodeId)
xmlAddNextSibling.
Sourcepub fn xml_add_prev_sibling(&mut self, cur: NodeId, elem: NodeId)
pub fn xml_add_prev_sibling(&mut self, cur: NodeId, elem: NodeId)
xmlAddPrevSibling.
Sourcepub fn xml_unlink_node(&mut self, id: NodeId)
pub fn xml_unlink_node(&mut self, id: NodeId)
xmlUnlinkNode.
Sourcepub fn xml_replace_node(&mut self, old: NodeId, new: NodeId) -> NodeId
pub fn xml_replace_node(&mut self, old: NodeId, new: NodeId) -> NodeId
xmlReplaceNode.
Sourcepub fn add_attr_owned(
&mut self,
elem: NodeId,
name: String,
prefix: Option<String>,
value: String,
) -> NodeId
pub fn add_attr_owned( &mut self, elem: NodeId, name: String, prefix: Option<String>, value: String, ) -> NodeId
As XmlDoc::add_attr, but takes ownership. The borrowing form has to
allocate a fresh String for the name, the prefix and the value, all of
which the parser already owns.
pub fn add_attr( &mut self, elem: NodeId, name: &str, prefix: Option<&str>, value: &str, ) -> NodeId
pub fn push_ns_def(&mut self, elem: NodeId, prefix: Option<String>, uri: String)
Sourcepub fn xml_has_prop(&self, node: NodeId, name: &str) -> bool
pub fn xml_has_prop(&self, node: NodeId, name: &str) -> bool
xmlHasProp.
Sourcepub fn xml_unset_prop(&mut self, node: NodeId, name: &str) -> bool
pub fn xml_unset_prop(&mut self, node: NodeId, name: &str) -> bool
xmlUnsetProp.
Sourcepub fn xml_node_get_content(&self, id: NodeId) -> String
pub fn xml_node_get_content(&self, id: NodeId) -> String
xmlNodeGetContent — concatenate descendant text/CDATA.
Sourcepub fn xml_node_set_content(&mut self, id: NodeId, content: &str)
pub fn xml_node_set_content(&mut self, id: NodeId, content: &str)
xmlNodeSetContent — replace children with a single text node.
Sourcepub fn xml_is_blank_node(&self, id: NodeId) -> bool
pub fn xml_is_blank_node(&self, id: NodeId) -> bool
xmlIsBlankNode.
Sourcepub fn xml_search_ns(
&self,
node: NodeId,
prefix: Option<&str>,
) -> Option<String>
pub fn xml_search_ns( &self, node: NodeId, prefix: Option<&str>, ) -> Option<String>
xmlSearchNs — walk ancestors for a prefix binding.
Sourcepub fn xml_new_ns(&mut self, node: NodeId, href: &str, prefix: Option<&str>)
pub fn xml_new_ns(&mut self, node: NodeId, href: &str, prefix: Option<&str>)
xmlNewNs — add a namespace declaration on an element.
Sourcepub fn xml_set_ns(
&mut self,
node: NodeId,
href: Option<&str>,
prefix: Option<&str>,
)
pub fn xml_set_ns( &mut self, node: NodeId, href: Option<&str>, prefix: Option<&str>, )
xmlSetNs.
Sourcepub fn xml_copy_doc(&self) -> XmlDoc
pub fn xml_copy_doc(&self) -> XmlDoc
xmlCopyDoc — deep copy.
pub fn qname(&self, id: NodeId) -> String
pub fn children(&self, id: NodeId) -> NodeIter<'_> ⓘ
pub fn attrs(&self, id: NodeId) -> NodeIter<'_> ⓘ
pub fn len(&self) -> usize
Source§impl XmlDoc
impl XmlDoc
Sourcepub fn xml_copy_children_from(
&mut self,
src: &XmlDoc,
src_parent: NodeId,
dst_parent: NodeId,
)
pub fn xml_copy_children_from( &mut self, src: &XmlDoc, src_parent: NodeId, dst_parent: NodeId, )
Deep-copy every child of src_parent in src under dst_parent here.
Needed because an entity whose replacement text contains markup has to
become NODES, not the escaped text of that markup. <!ENTITY e "<b>x</b>"> used in content produced the literal string <b>x</b> in
the tree, so anything reading the document for structure got garbage
and DTD validation saw character data where an element was declared.
Iterative, like every other traversal here: the replacement is attacker-supplied and may be arbitrarily deep.