Expand description
§use-xml
Practical XML utility primitives for lightweight declaration, element, attribute, escaping, and comment handling.
Warning: versions below
0.3.0are 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
truewhen an element has the named attribute. - has_
xml_ declaration - Returns
truewhen the input starts with an XML declaration. - looks_
like_ xml - Returns
truewhen 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.