Module jupiter::ig::xml

source ·
Expand description

Permits to load XML data using a pull principle.

Using this facility permits to load large XML files in a very performant way. By providing external work buffer a zero copy operation can be achieved (unless a non UTF-8 encoding is used).

As the XML data being processed is most probably large and not needed all at once, the pull strategy operates on a “per element” level for which then child elements can be queried and processed like so:

use jupiter::ig::xml::PullReader;
use std::io::BufReader;

let data = r#"
<xml>
    <entry><name>42</name><value>foo</value></entry>
</xml>
"#;

let mut reader = PullReader::new(data.as_bytes());
let mut root_element = reader.root().unwrap();
if let Ok(Some(mut entry)) = root_element.next_child() {
    assert_eq!(entry.name().as_ref(), "entry");
    if let Ok(Some(mut child)) = entry.find_next_child("name") {
        assert_eq!(child.text().unwrap().contents().as_ref(), "42");
    } else {
        panic!("Invalid XML!");
    };
    if let Ok(Some(mut child)) = entry.next_child() {
        assert_eq!(child.name().as_ref(), "value");
        assert_eq!(child.text().unwrap().contents().as_ref(), "foo");
    } else {
        panic!("Invalid XML!");
    };
} else {
    panic!("Invalid XML!");
};

§Memory Management

The underlying quick_xml library uses an external buffer management when reading events. While this is probably the most efficient way of dealing with memory management, we provide an internal buffer manager which takes care of this task so that the code required to process XML data isn’t polluted with these tasks.

We still re-use buffers as much as possible and therefore can still provide excellent performance while also providing a convenient API. Note however, that in order to minimize the performance overhead, we need some unsafe blocks.

Structs§

  • Provides an encoding aware view on an attribute of an Element.
  • Provides an encoding aware view on the attributes of an Element.
  • Represents a matched element while processing XML data.
  • Provides a high level abstraction above Reader as provided by quick_xml.
  • Provides an encoding aware handle which represents the text contents of an Element.