Crate exile

Crate exile 

Source
Expand description

build

exile is a Rust library for reading and writing XML.

The goal, at least initially, is to provide an abstract syntax tree of an XML file. As such, this is a Exile is a dom parser and loads the complete contents of the document into memory.

Currently supported:

  • Attributes
  • CDATA Sections
  • Comment Parsing
  • Elements
  • Processing Instructions
  • Text Nodes
  • UTF-8
  • Whitespace Normalization

Not Supported:

  • Doctypes
  • Entities
  • Entity References
  • Other Encodings
  • Whitesace Preservation: All text nodes are treated as if whitespace collapse were in-effect.

§Example

Parsing XML looks like this.

let xml = r#"
<root>
  <thing name="foo"/>
  <thing>bar</thing>
</root>
"#;

let doc = exile::parse(xml).unwrap();
for child in doc.root().children() {
    println!("element name: {}", child.name());
    if let Some(attribute) = child.attribute("name") {
        println!("name attribute: {}", attribute);
    }
}

// we can create an index of elements
let index = doc.index();

// the element at index 2 is <thing>bar</thing>
let thing = index.element(2).unwrap();

// the parent of index 2 is <root>
let root = index.parent(&thing).unwrap();

assert_eq!("bar", thing.text().unwrap());
assert_eq!("root", root.name());

Authoring XML looks like this.

use exile::{Document, Element, Node};
let mut root = Element::from_name("my_root");
root.add_attribute("foo", "bar");
let mut child = Element::from_name("my_child");
child.add_text("Hello World!");
root.add_child(child);
let doc = Document::from_root(root);
println!("{}", doc.to_string());

The above program prints:

<my_root foo="bar">
  <my_child>Hello World!</my_child>
</my_root>

Re-exports§

pub use crate::parser::ParseError;

Modules§

error
The public error type for this library. !
parser
This module is responsible for parsing XML from string representations. !

Structs§

Declaration
The XML declaration at the start of the XML Document.
Document
Represents an XML Document.
Element
Represents an Element in an XML Document.
Index
Produces an index for each Element in the [`Document’]. Provides lookups for an element’s parent. This requires ownership of the document and pins the document.
Namespace
An XML namespace is defined by a URI and has a local name to serve as an alias. If the namespace is declared without a local name, then it serves as a default namespace.
NcName
https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NCName [4] NCName ::= (Letter | ‘_’) (NCNameChar)* /* An XML Name, minus the “:” */
Pi
Represents a Processing Instruction (PI) in an XML document.
QName
Qualified Name
WriteOpts
Options for controlling how the XML Document is written when serialized.

Enums§

Encoding
The encoding of the XML Document, currently only UTF-8 is supported.
Misc
Represents a “Misc” entry, which is a Processing Instruction (PI), Comment, or Whitespace. These are the types of nodes allowed in the prologue and epilogue of an XML document.
Node
Represents a Node in an XML Document. The Document consists of a recursive nesting of these.
NsErr
The error type for errors related to the parsing of namespace strings.
Version
Represents the XML Version being used.

Functions§

load
Load a document from a file.
parse
Parse an XML file held in string contents.