Skip to main content

XmlDoc

Struct XmlDoc 

Source
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: String

XML 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/>&#32;<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>&empty;</foo> against EMPTY is content, and the tree has no node to show for it.

Implementations§

Source§

impl XmlDoc

Source

pub fn xml_new_doc(version: Option<&str>) -> Self

xmlNewDoc.

Source

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.

Source

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.

Source

pub fn node(&self, id: NodeId) -> &Node

Source

pub fn node_mut(&mut self, id: NodeId) -> &mut Node

Source

pub fn kind(&self, id: NodeId) -> NodeKind

Source

pub fn name(&self, id: NodeId) -> &str

Source

pub fn prefix(&self, id: NodeId) -> Option<&str>

Source

pub fn ns_uri(&self, id: NodeId) -> Option<&str>

Source

pub fn content(&self, id: NodeId) -> &str

Source

pub fn parent(&self, id: NodeId) -> Option<NodeId>

Source

pub fn first_child(&self, id: NodeId) -> Option<NodeId>

Source

pub fn last_child(&self, id: NodeId) -> Option<NodeId>

Source

pub fn next_sibling(&self, id: NodeId) -> Option<NodeId>

Source

pub fn prev_sibling(&self, id: NodeId) -> Option<NodeId>

Source

pub fn first_attr(&self, id: NodeId) -> Option<NodeId>

Source

pub fn ns_defs(&self, id: NodeId) -> &[(Option<String>, String)]

Source

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.

Source

pub fn alloc(&mut self, kind: NodeKind, name: impl Into<String>) -> NodeId

Source

pub fn xml_doc_get_root_element(&self) -> Option<NodeId>

xmlDocGetRootElement.

Source

pub fn xml_doc_set_root_element(&mut self, elem: NodeId) -> Option<NodeId>

xmlDocSetRootElement. Returns the previous root, if any.

Source

pub fn xml_new_node(&mut self, ns_uri: Option<&str>, name: &str) -> NodeId

xmlNewNode.

Source

pub fn xml_new_doc_node( &mut self, ns_uri: Option<&str>, name: &str, content: Option<&str>, ) -> NodeId

xmlNewDocNode.

Source

pub fn xml_new_child( &mut self, parent: NodeId, ns_uri: Option<&str>, name: &str, content: Option<&str>, ) -> NodeId

xmlNewChild.

Source

pub fn xml_add_child(&mut self, parent: NodeId, child: NodeId)

xmlAddChild.

Source

pub fn xml_add_next_sibling(&mut self, cur: NodeId, elem: NodeId)

xmlAddNextSibling.

Source

pub fn xml_add_prev_sibling(&mut self, cur: NodeId, elem: NodeId)

xmlAddPrevSibling.

xmlUnlinkNode.

Source

pub fn xml_replace_node(&mut self, old: NodeId, new: NodeId) -> NodeId

xmlReplaceNode.

Source

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.

Source

pub fn add_attr( &mut self, elem: NodeId, name: &str, prefix: Option<&str>, value: &str, ) -> NodeId

Source

pub fn push_ns_def(&mut self, elem: NodeId, prefix: Option<String>, uri: String)

Source

pub fn xml_set_prop(&mut self, node: NodeId, name: &str, value: &str) -> NodeId

xmlSetProp.

Source

pub fn xml_get_prop(&self, node: NodeId, name: &str) -> Option<String>

xmlGetProp.

Source

pub fn xml_has_prop(&self, node: NodeId, name: &str) -> bool

xmlHasProp.

Source

pub fn xml_unset_prop(&mut self, node: NodeId, name: &str) -> bool

xmlUnsetProp.

Source

pub fn xml_node_get_content(&self, id: NodeId) -> String

xmlNodeGetContent — concatenate descendant text/CDATA.

Source

pub fn xml_node_set_content(&mut self, id: NodeId, content: &str)

xmlNodeSetContent — replace children with a single text node.

Source

pub fn xml_is_blank_node(&self, id: NodeId) -> bool

xmlIsBlankNode.

Source

pub fn xml_search_ns( &self, node: NodeId, prefix: Option<&str>, ) -> Option<String>

xmlSearchNs — walk ancestors for a prefix binding.

Source

pub fn xml_new_ns(&mut self, node: NodeId, href: &str, prefix: Option<&str>)

xmlNewNs — add a namespace declaration on an element.

Source

pub fn xml_set_ns( &mut self, node: NodeId, href: Option<&str>, prefix: Option<&str>, )

xmlSetNs.

Source

pub fn xml_copy_doc(&self) -> XmlDoc

xmlCopyDoc — deep copy.

Source

pub fn qname(&self, id: NodeId) -> String

Source

pub fn children(&self, id: NodeId) -> NodeIter<'_>

Source

pub fn attrs(&self, id: NodeId) -> NodeIter<'_>

Source

pub fn len(&self) -> usize

Source§

impl XmlDoc

Source

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.

Trait Implementations§

Source§

impl Clone for XmlDoc

Source§

fn clone(&self) -> XmlDoc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for XmlDoc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for XmlDoc

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.