Skip to main content

Module reader

Module reader 

Source
Expand description

Pull-based streaming XML reader API.

The XmlReader provides a cursor-style, pull-based interface for reading XML documents. Instead of building a full tree in memory or requiring callback implementations (SAX), the reader advances one node at a time through the document, exposing the current node’s properties via accessor methods.

This API is similar to libxml2’s xmlTextReader and .NET’s XmlReader.

§Usage Pattern

Call XmlReader::read repeatedly to advance through the document. Each call moves the cursor to the next node. Use accessor methods like XmlReader::node_type, XmlReader::name, and XmlReader::value to inspect the current node. When read() returns Ok(false), the end of the document has been reached.

§Examples

use xmloxide::reader::{XmlReader, XmlNodeType};

let mut reader = XmlReader::new("<root><child>Hello</child></root>");
let mut elements = Vec::new();

while reader.read().unwrap() {
    if reader.node_type() == XmlNodeType::Element {
        elements.push(reader.name().unwrap_or_default().to_string());
    }
}

assert_eq!(elements, vec!["root", "child"]);

Structs§

XmlReader
A pull-based streaming XML reader.

Enums§

XmlNodeType
The type of the current node in the reader.