Crate xml_dom

A Rust crate providing a reasonably faithful implementation of the W3C Document Object Model Core, Level 2.

MIT License Minimum Rust Version crates.io docs.rs GitHub stars

This crate provides a trait-based implementation of the DOM with minimal changes to the style and semantics defined in the Level 2 specification. The specific mapping from the IDL in the specification is described in the documentation, however from a purely style point of view the implementation has the following characteristics:

  1. It maintains a reasonable separation between the node type traits and the tree implementation using opaque Node reference types.
  2. Where possible the names from IDL are used with minimal conversion, however some redundant suffixes (_data, _node) have been reduced for brevity/clarity.
  3. This leads to a replication of the typical programmer experience where casting between the node traits is required. This is supported by the xml_dom::convert module.

Example

```rust use xmldom::*; use xmldom::convert::*;

let implementation = getimplementation(); let mut documentnode = implementation .create_document("http://www.w3.org/1999/xhtml", "html", None) .unwrap();

let document = asdocumentmut(&mut documentnode).unwrap(); let mut rootnode = document.document_element().unwrap();

let root = aselementmut(&mut rootnode).unwrap(); root.setattribute("lang", "en"); let head = root.appendchild(document.createelement("head").unwrap()); let _body = root.appendchild(document.create_element("body").unwrap());

let xml = documentnode.tostring(); println!("HTML: {}", xml); ```

Changes

Version 0.1.1 (in progress)

Version 0.1.0

TODO

  1. Currently does not support DocumentFragment, Entity, EntityReference, or Notation.
  2. Not intending to be schema-aware, so Document::get_element_by_id always returns None.
  3. A lot of required methods are still unimplemented!().
  4. Intend to add reader feature to de-serialize using crate quick_xml.