Skip to main content

Crate use_xml

Crate use_xml 

Source
Expand description

§use-xml

Practical XML utility primitives for lightweight declaration, element, attribute, escaping, and comment handling.

Warning: versions below 0.3.0 are experimental and may change as the crate matures.

§Example Usage

use use_xml::{extract_root_element, get_attribute, has_xml_declaration, strip_xml_comments};

let input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root id=\"42\"><!-- note --></root>";
let root = extract_root_element(input).unwrap();

assert!(has_xml_declaration(input));
assert_eq!(root.name, "root");
assert_eq!(get_attribute("<root id=\"42\" />", "id"), Some("42".to_string()));
assert_eq!(strip_xml_comments("<root><!-- note --><child /></root>"), "<root><child /></root>");

§Scope

  • XML declaration detection and conservative extraction
  • root element and attribute inspection helpers
  • XML escaping, unescaping, and comment stripping

§Non-Goals

  • a full XML parser
  • XPath support
  • XSD validation
  • deep namespace resolution

§License

Licensed under either of the following, at your option:

  • MIT License
  • Apache License, Version 2.0

Structs§

XmlAttribute
A simple XML attribute.
XmlDeclaration
A conservative view of an XML declaration.
XmlElement
A simple XML start element.

Functions§

escape_xml
Escapes XML text content.
extract_attributes
Extracts attributes from an element start tag.
extract_root_element
Extracts the root element start tag when present.
extract_xml_declaration
Extracts the XML declaration when present.
get_attribute
Returns the named attribute from an element when present.
has_attribute
Returns true when an element has the named attribute.
has_xml_declaration
Returns true when the input starts with an XML declaration.
looks_like_xml
Returns true when the input looks like XML.
strip_xml_comments
Strips XML comments from the input.
strip_xml_declaration
Strips a leading XML declaration when present.
unescape_xml
Unescapes the most common XML entities.