Skip to main content

Dtd

Struct Dtd 

Source
pub struct Dtd {
    pub elements: HashMap<String, ElementDecl>,
    pub element_order: Vec<String>,
    pub attlists: HashMap<String, Vec<AttDecl>>,
    pub root_name: String,
    pub public_id: Option<String>,
    pub system_id: Option<String>,
    pub unparsed_entities: HashMap<String, UnparsedEntity>,
    pub entities: Vec<EntityDecl>,
    pub decl_order: Vec<DeclRef>,
    pub internal_decls: Vec<String>,
    pub internal_subset_prolog_index: u32,
}
Expand description

Parsed DTD content used by [validate]. Built up incrementally by the bytes-reader as it encounters <!ELEMENT> / <!ATTLIST> declarations in the internal subset.

Fields§

§elements: HashMap<String, ElementDecl>

Element declarations keyed by element name.

§element_order: Vec<String>

Element names in declaration order — the order libxml2 keeps in xmlDtd.children, which lxml’s DTD.elements() exposes. The elements map is for lookup; this preserves source order.

§attlists: HashMap<String, Vec<AttDecl>>

Attribute declarations keyed by element name. libxml2’s ATTLIST groups can append (multiple <!ATTLIST elem ...> for the same elem are merged here).

§root_name: String

Root element name from the DOCTYPE header: <!DOCTYPE root_name ...>. Populated for any successfully-parsed doctype, even one with no internal subset and no external ID. Empty when the document has no DOCTYPE at all.

§public_id: Option<String>

PUBLIC "..." identifier from the DOCTYPE header, when present. None for SYSTEM-only or no external ID.

§system_id: Option<String>

SYSTEM "..." identifier (or the second literal of a PUBLIC "..." "..." form) from the DOCTYPE header. None when the header has no external ID.

§unparsed_entities: HashMap<String, UnparsedEntity>

Unparsed external general entities — those declared with an NDATA annotation per XML 1.0 § 4.2.2. Keyed by entity name; the value carries the SYSTEM identifier (the URI a non-XML processor would fetch) and the PUBLIC identifier when present. Used by XSLT’s unparsed-entity-uri() / unparsed-entity-public-id() functions (XSLT 1.0 § 12.4).

§entities: Vec<EntityDecl>

General <!ENTITY> declarations in source order — what lxml’s DTD.entities() exposes and the DTD serializer reconstructs. Carries internal, external, and unparsed entities (a superset of unparsed_entities) plus parameter entities (flagged parameter).

§decl_order: Vec<DeclRef>

Declaration references in source order, so the DTD serializer can reproduce libxml2’s xmlDtd.children ordering.

§internal_decls: Vec<String>

Raw markup declarations from the internal subset, in document order, each as it appeared in source (<!ENTITY …>, <!ELEMENT …>, <!ATTLIST …>, <!NOTATION …>). Captured for round-trip serialization of the DOCTYPE’s [ … ] body; empty when the document had no internal subset. Only declarations read directly from the source are captured (not those produced by parameter-entity expansion).

§internal_subset_prolog_index: u32

Number of document-level comments/PIs that preceded the <!DOCTYPE …> in the prolog. Lets the compat layer splice the internal-subset node into the document’s sibling chain at its true position (misc[..k] → DOCTYPE → misc[k..] → root) so a comment that came before the DOCTYPE serializes before it, as libxml2 does. Zero when the DOCTYPE was the first prolog item (the common case) or when there is no DOCTYPE.

Implementations§

Source§

impl Dtd

Source

pub fn new() -> Self

Empty DTD — no declarations.

Source

pub fn is_empty(&self) -> bool

true when no element or attribute declarations have been captured. Used as a fast-path skip in the validator.

Source

pub fn add_element(&mut self, decl: ElementDecl)

Insert (or replace) an element declaration. libxml2’s behaviour on duplicate <!ELEMENT name ...> for the same name is to emit a warning and keep the first declaration; we keep the first too (this matches the de-facto standard across major parsers).

Source

pub fn add_attlist(&mut self, element: String, decls: Vec<AttDecl>)

Append attribute declarations for an element. Multiple <!ATTLIST elem ...> blocks merge — XML 1.0 § 3.3.

Trait Implementations§

Source§

impl Clone for Dtd

Source§

fn clone(&self) -> Dtd

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dtd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dtd

Source§

fn default() -> Dtd

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Dtd

§

impl RefUnwindSafe for Dtd

§

impl Send for Dtd

§

impl Sync for Dtd

§

impl Unpin for Dtd

§

impl UnsafeUnpin for Dtd

§

impl UnwindSafe for Dtd

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.