roxml 0.4.0

Read-only, zero-copy, lazy XML reader for no_std environments, without allocation
Documentation
// Copyright © 2026 Stephan Kunz
//! DOCTYPE declaration node.

use core::ops::Range;

/// A DOCTYPE declaration: `<!DOCTYPE … >`.
///
/// Only the raw content between `<!DOCTYPE` and `>` is exposed; internal
/// subsets and external references are not parsed further. Entities declared
/// in an internal subset are not used for decoding.
#[derive(Clone)]
pub struct XmlDoctype<'xml> {
	pub(crate) xml_text: &'xml str,
	/// Byte range of the full `<!DOCTYPE … >` in the source.
	pub(crate) range: Range<usize>,
}

impl<'xml> XmlDoctype<'xml> {
	/// Raw content between `<!DOCTYPE` and `>`, trimmed of leading/trailing
	/// ASCII whitespace. Includes an internal subset `[ … ]`.
	///
	/// # Examples
	/// ```
	/// use roxml::prelude::*;
	///
	/// let xml = "<!DOCTYPE note [ <!ELEMENT note (#PCDATA)> ]><note/>";
	/// let Some(PrologNode::Doctype(doctype)) = XmlReader::parse(xml).prolog().next() else {
	///     panic!("no doctype");
	/// };
	/// assert_eq!(doctype.content(), "note [ <!ELEMENT note (#PCDATA)> ]");
	/// ```
	#[must_use]
	pub fn content(&self) -> &'xml str {
		let s = &self.xml_text[self.range.clone()];
		// s starts with "<!DOCTYPE" (9 bytes) and ends with ">"
		s[9..s.len() - 1].trim()
	}

	/// Byte range of this node in the source text.
	#[must_use]
	pub fn range(&self) -> Range<usize> {
		self.range.clone()
	}
}