NAME

oEdtk::XML::DTD - parse and validate XML documents against their DTD

SYNOPSIS

use oEdtk::XML::DTD;

my ($dom, $public_id) =
    oEdtk::XML::DTD::parse_and_validate_xml_file($file, \@accepted_ids);

DESCRIPTION

Parse an XML document and check its DTD public identifier against a list of accepted ones before checking that the document validates. The module was formed at S21 of the fork-merge plan by merging the 0.8032 fork's oEdtk::XML::DTD and oEdtk::XML::DTD::Utils (about 90% identical); the XSD variant it used to carry now lives in oEdtk::XML::XSD, and oEdtk::XML::DTD::Utils remains loadable as a delegate.

FUNCTIONS

parse_and_validate_xml_file

parse_and_validate_xml_file($file, \@accepted_public_ids, $flag_fatal);

Parse $file and validate it. When $flag_fatal is false the failures are reported and the function returns instead of dying. Returns ($dom, $public_id).

parse_and_validate_xml_string

parse_and_validate_xml_string($xml, \@accepted_public_ids, $flag_fatal);

The same, from a string.

parse_xml

parse_xml($input, $type, \@accepted_public_ids, $msg, $flag_fatal);

The shared step behind the two wrappers above; $type is 'file' or 'string'.

validate_xml

my ($dom, $public_id) = validate_xml($dom, \@accepted_public_ids, $msg, $flag_fatal);

Check the public identifier of an already parsed document and that it validates. The public identifier is read through internalSubset, which returns the DTD node when the document declares a DOCTYPE and undef otherwise, so a document without a DOCTYPE reports an empty public id rather than crashing.

parse_and_validate_xml_file_xsd

parse_and_validate_xml_file_xsd($file, $xsd_schema);

Forward to oEdtk::XML::XSD, kept so the fork's callers keep working.

load_xml_catalogs

load_xml_catalogs($parser);

Load the XML catalogs named by the EDTK_XML_CATALOG_FILES configuration key.

list_children_nodes

my @nodes = list_children_nodes($node, @authorized_names);

Return the element children of $node, refusing unexpected names, non-empty text and unexpected node types.

xml_to_txt

my $text = xml_to_txt($string);

Drop a leading <?xml ... ?> declaration and decode the hexadecimal numeric entities that follow it; croak on any entity left undecoded.

first_id

my $id = first_id($root);

Return the first of the id/@numaba, id/@external and id/@phoenix attributes, and croak when none of them exists.

xpath

my $value = xpath($node, $path, $required);

Return the value of the $path attribute of $node, croaking when it is missing and $required is true.

found_in_list

my $ok = found_in_list($value, \@list);

True when $value equals one element of \@list.

AUTHOR

The oEdtk team.