Struct quick_xml::XmlReader [] [src]

pub struct XmlReader<B: BufRead> {
    // some fields omitted
}

A Xml reader

Consumes a BufRead and streams xml Events

use quick_xml::{XmlReader, Event};

let xml = r#"<tag1 att1 = "test">
                <tag2><!--Test comment-->Test</tag2>
                <tag2>Test 2</tag2>
            </tag1>"#;
let reader = XmlReader::from(xml).trim_text(true);
let mut count = 0;
let mut txt = Vec::new();
for r in reader {
    match r {
        Ok(Event::Start(ref e)) => {
            match e.name() {
                b"tag1" => println!("attributes values: {:?}",
                                    e.attributes()
                                    .map(|a| a.unwrap().1)
                                    .collect::<Vec<_>>()),
                b"tag2" => count += 1,
                _ => (),
            }
        },
        Ok(Event::Text(e)) => txt.push(e.into_string()),
        Err((e, pos)) => panic!("{:?} at position {}", e, pos),
        _ => (),
    }
}

Methods

impl<B: BufRead> XmlReader<B>
[src]

Creates a XmlReader from a generic BufReader

Converts into a XmlnsReader iterator

Change expand_empty_elements default behaviour (true per default)

When set to true, all Empty events are expanded into an Open event followed by a Close Event.

Change trim_text default behaviour (false per default)

When set to true, all Text events are trimed. If they are empty, no event if pushed

Change default with_check (true per default)

When set to true, it won't check if End node match last Start node. If the xml is known to be sane (already processed etc ...) this saves extra time

Change default check_comment (false per default)

When set to true, every Comment event will be checked for not containing -- Most of the time we don't want comments at all so we don't really care about comment correctness, thus default value is false for performance reason

Reads until end element is found

Manages nested cases where parent and child elements have the same name

Reads next event, if Event::Text or Event::End, then returns a String, else returns an error

Gets the current BufRead position Useful when debugging errors

impl XmlReader<BufReader<File>>
[src]

Creates a xml reader from a file path

Trait Implementations

impl<B: Clone + BufRead> Clone for XmlReader<B>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> From<&'a str> for XmlReader<&'a [u8]>
[src]

Performs the conversion.

impl<B: BufRead> Iterator for XmlReader<B>
[src]

Iterator on xml returning Events

The type of the elements being iterated over.

Advances the iterator and returns the next value. Read more

Returns the bounds on the remaining length of the iterator. Read more

Consumes the iterator, counting the number of iterations and returning it. Read more

Consumes the iterator, returning the last element. Read more

Consumes the n first elements of the iterator, then returns the next() one. Read more

Takes two iterators and creates a new iterator over both in sequence. Read more

'Zips up' two iterators into a single iterator of pairs. Read more

Takes a closure and creates an iterator which calls that closure on each element. Read more

Creates an iterator which uses a closure to determine if an element should be yielded. Read more

Creates an iterator that both filters and maps. Read more

Creates an iterator which gives the current iteration count as well as the next value. Read more

Creates an iterator which can use peek to look at the next element of the iterator without consuming it. Read more

Creates an iterator that [skip()]s elements based on a predicate. Read more

Creates an iterator that yields elements based on a predicate. Read more

Creates an iterator that skips the first n elements. Read more

Creates an iterator that yields its first n elements. Read more

An iterator adaptor similar to [fold()] that holds internal state and produces a new iterator. Read more

Creates an iterator that works like map, but flattens nested structure. Read more

Creates an iterator which ends after the first None. Read more

Do something with each element of an iterator, passing the value on. Read more

Borrows an iterator, rather than consuming it. Read more

Transforms an iterator into a collection. Read more

Consumes an iterator, creating two collections from it. Read more

An iterator adaptor that applies a function, producing a single, final value. Read more

Tests if every element of the iterator matches a predicate. Read more

Tests if any element of the iterator matches a predicate. Read more

Searches for an element of an iterator that satisfies a predicate. Read more

Searches for an element in an iterator, returning its index. Read more

Searches for an element in an iterator from the right, returning its index. Read more

Returns the maximum element of an iterator. Read more

Returns the minimum element of an iterator. Read more

Returns the element that gives the maximum value from the specified function. Read more

Returns the element that gives the minimum value from the specified function. Read more

Reverses an iterator's direction. Read more

Converts an iterator of pairs into a pair of containers. Read more

Creates an iterator which clone()s all of its elements. Read more

Repeats an iterator endlessly. Read more

Sums the elements of an iterator. Read more

Iterates over the entire iterator, multiplying all the elements Read more

Lexicographically compares the elements of this Iterator with those of another. Read more

Lexicographically compares the elements of this Iterator with those of another. Read more

Determines if the elements of this Iterator are equal to those of another. Read more

Determines if the elements of this Iterator are unequal to those of another. Read more

Determines if the elements of this Iterator are lexicographically less than those of another. Read more

Determines if the elements of this Iterator are lexicographically less or equal to those of another. Read more

Determines if the elements of this Iterator are lexicographically greater than those of another. Read more

Determines if the elements of this Iterator are lexicographically greater than or equal to those of another. Read more