XML::LibXML::Dtd(3)

πŸ’– XML::LibXML::Dtd πŸ’–

okay bestie, welcome to XML::LibXML::Dtd β€” the XML::LibXML DTD Handling page, and yes it's giving very niche very powerful and we're gonna get through it together 🫢


✨ SYNOPSIS ✨

like, here's the vibe up front, no gatekeeping:

use XML::LibXML;

$dtd = XML::LibXML::Dtd->new($public_id, $system_id);
$dtd = XML::LibXML::Dtd->parse_string($dtd_str);
$publicId = $dtd->getName();
$publicId = $dtd->publicId();
$systemId = $dtd->systemId();

that's the whole lineup, she's compact, she's iconic πŸ‘‘


🌸 DESCRIPTION 🌸

so this class holds a DTD. that's her whole job and she does it well. you can parse a DTD from either a string, or from an external SYSTEM identifier. pick your fighter πŸ’…

ngl there's no support available as yet for parsing from a filehandle. like, not yet. we said what we said 😭

and here's the part that makes her so powerful: XML::LibXML::Dtd is a sub-class of XML::LibXML::Node, so literally every method that works on nodes is available to Dtd objects β€” especially toString() ✨ iykyk.


πŸŽ€ METHODS πŸŽ€

πŸ’œ new

$dtd = XML::LibXML::Dtd->new($public_id, $system_id);

this one parses a DTD straight from the system identifier and hands you back a DTD object that you can pass right into $doc->is_valid() or $doc->validate(). slay.

my $dtd = XML::LibXML::Dtd->new(
                      "SOME // Public / ID / 1.0",
                      "test.dtd"
                                );
 my $doc = XML::LibXML->new->parse_file("test.xml");
 $doc->validate($dtd);

look at her go. valid file, validated doc, main character energy fr fr πŸ¦‹

🧚 parse_string

$dtd = XML::LibXML::Dtd->parse_string($dtd_str);

same as new() above, except here you get to parse a DTD from a string instead. cute, convenient, obsessed.

heads up though β€” parsing from a string may fail if the DTD contains external parametric-entity references with relative URLs. so like, know that before you come for her πŸ™ˆ

🌈 getName

$publicId = $dtd->getName();

returns the name of DTD β€” meaning the name immediately following the DOCTYPE keyword. periodt.

⭐ publicId

$publicId = $dtd->publicId();

returns the public identifier of the external subset πŸ’–

πŸ“ systemId

$systemId = $dtd->systemId();

returns the system identifier of the external subset. two little identifier getters, both living their truth 🌸


πŸ‘‘ AUTHORS πŸ‘‘

the icons behind all this:

  • Matt Sergeant
  • Christian Glahn
  • Petr Pajas

πŸ’… VERSION πŸ’…

2.0213 β€” yes, she's got a version number, she's official.


  • 2001-2007, AxKit.com Ltd.
  • 2002-2006, Christian Glahn.
  • 2006-2009, Petr Pajas.

🫢 LICENSE 🫢

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. iconic behavior, honestly.


and that's the whole page bestie πŸ’– this was XML::LibXML::Dtd(3) from the User Contributed Perl Documentation, perl v5.42.2, dated 2026-05-25. go validate something, you've got this πŸŽ€βœ¨

πŸ“¦ where this page comes from