Skip to content

v1.0.0

Choose a tag to compare

@DraviaVemal DraviaVemal released this 17 Aug 06:45

Release Notes - draviavemal-xml_rs v1.0.0

I'm excited to announce the first stable release of draviavemal-xml_rs, a high-performance, memory-efficient XML DOM parser for Rust. As a solo developer, this release marks the culmination of my extensive development and testing to provide a robust XML parsing and manipulation library for Rust developers.

🌟 Highlights

  • Full DOM Implementation: Complete XML Document Object Model support with element, attribute, and text manipulation
  • Namespace-Aware Parsing: Proper handling of XML namespaces with prefix-to-URI resolution
  • Order-Preserving Attributes: Maintains the original order of XML attributes
  • Round-Trip Safe: Serialization preserves namespace prefixes, attribute order, and original structure
  • Low Memory Footprint: Efficient ID-based tree model (similar to arena allocation)
  • Zero Unsafe Code: Implemented entirely in safe Rust

✨ Features

XML Parsing and Serialization

  • UTF-8 Focused: Optimized for the most common XML encoding
  • XML Declaration Support: Reads version, encoding, and standalone attributes
  • Line Break Normalization: Converts \r\n and \r to \n for consistent handling
  • Special Character Handling: Proper escaping and unescaping of XML special characters (<, >, &, ", ')
  • Comment Preservation: Maintains comment nodes in the document

Namespace Support

  • Full Namespace Resolution: Correctly handles namespaced elements and attributes
  • QName Parsing: Properly resolves {namespace_uri, local_name} format
  • Namespace Stacks: Maintains nested namespace contexts
  • Alias Renaming: Ability to modify namespace prefixes while preserving URIs

Document Manipulation

  • Element Creation and Modification: Comprehensive API for building and editing XML documents
  • Attribute Manipulation: Add, remove, and modify element attributes
  • Child Element Management: Find, add, and remove child elements
  • Content Operations: Add text, comments, and mixed content to elements

Search and Navigation

  • Element Finding: Find elements by tag name or attributes
  • Attribute Searching: Locate elements with specific attribute values
  • Namespace-Aware Queries: Search with or without namespace awareness

πŸ“‹ API Documentation

The library provides a clean, well-documented API organized into several key components:

Core Types

  • XmlDocument: The container for the entire XML document tree
  • XmlElement: Represents a single XML element with its attributes and contents
  • XmlAttribute: Represents an XML attribute with name and value
  • XmlNamespace: Manages namespace prefix-to-URI mappings
  • XmlElementContentType: Represents different types of content (Element, Text, Comment)

Serialization/Deserialization

  • XmlDeserializer: Parses XML text into a document object model
  • XmlSerializer: Converts document object models back to XML text

πŸ”§ Technical Details

  • Memory Model: Uses a node ID system with centralized storage for efficient memory use
  • Error Handling: Comprehensive error reporting using the anyhow crate
  • Validation: XML name validation according to W3C specifications
  • Performance: Optimized for both parsing and manipulation operations

πŸ“¦ Installation

Add to your Cargo.toml:

[dependencies]
draviavemal-xml_rs = "1.0.0"

Or use Cargo:

cargo add draviavemal-xml_rs

πŸ“– Basic Usage

use draviavemal_xml_rs::{XmlDeserializer, XmlSerializer, XmlDocument, XmlAttribute};

// Parse XML from a string
let xml_string = r#"<root><child id="1">Text content</child></root>"#;
let mut document = XmlDeserializer::vec_to_xml_doc_tree(xml_string.as_bytes().to_vec())
    .expect("Failed to parse XML");

// Access elements
let root_id = document.get_root_id();
let child_id = document.find_first_child(root_id, "child")
    .expect("Failed to find child")
    .expect("No child element found");

// Create new elements
let new_child_id = document.append_child_element_mut(
    root_id,
    "new-child",
    Some(vec![XmlAttribute::new("type".to_string(), "example".to_string())])
).expect("Failed to create new child");

// Serialize back to XML
let xml_bytes = XmlSerializer::xml_tree_to_vec(&mut document)
    .expect("Failed to serialize XML");
let xml_output = String::from_utf8(xml_bytes).expect("Invalid UTF-8");

πŸ“œ License

  • Open Source: AGPL-3.0 license for non-commercial and open source use
  • Commercial: Separate licensing available via sponsorship

πŸ”œ Future Plans

As I continue to develop this library, I plan to focus on:

  • Performance optimizations
  • Additional convenience APIs
  • XPath-like querying capabilities
  • Schema validation support
  • Enhanced documentation and examples

I welcome feedback and feature requests to help prioritize future development.

For more information, visit GitHub Repository or Documentation.