roxml 0.4.1

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

use core::{fmt, 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
	/// whitespace as [`str::trim`] does, i.e. Unicode 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()
	}
}

impl fmt::Debug for XmlDoctype<'_> {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		f.debug_struct("XmlDoctype")
			.field("content", &self.content())
			.field("range", &self.range)
			.finish()
	}
}