Name
Dita::Validate - Check that a level of an XML parse tree conforms to the Dita standard without resorting to either the DitaOT or xmllint.
Synopsis
Given a child node of an xml parse tree produced by Data::Edit::Xml confirm that said child can be reached from its parent via the intervening siblings along a path conforming to the Dita standard without the overhead of invoking either the DitaOT toolkit or xmllint.
Description
Check that a level of an XML parse tree conforms to the
Version q(20191016).
The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.
Validate
Check that a level of an XML parse tree conforms to the Dita standard without resorting to either the DITA-OT or xmllint.
validateChild($)
Confirm that the given child node is both reachable and allowed in its current position. Return 0 for parent is not in Dita, 1 for not reachable (presumably a prior sibling is in error), 2 - reachable and invalid, 3 - reachable and valid. Note that the root node is always reachable and valid.
Parameter Description
1 $node Node in a L<Data::Edit::Xml|https://metacpan.org/pod/Data::Edit::Xml> parse tree
Example:
if (1)
{my $x = Data::Edit::Xml::new(<<END);
<concept>
<title>aaa</title>
<conbody>
<p>aaa</p>
<p><ol><li/><LI/><li/></ol></p>
<q>ccc</q>
<p>ddd</p>
</conbody>
</concept>
END
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x);
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_title);
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody);
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p);
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p_1);
ok 2 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_q);
ok 1 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p_2);
ok 3 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p_1_ol_li);
ok 2 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p_1_ol_LI);
ok 1 == 𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗲𝗖𝗵𝗶𝗹𝗱($x->go_conbody_p_1_ol_li_1);
my $ol = $x->go_conbody_p_1_ol;
my $LI = $x->go_conbody_p_1_ol_LI;
ok $LI == firstFailure($ol);
ok $LI == firstFailure($LI);
}
This is a static method and so should be invoked as:
Dita::Validate::validateChild
firstFailure($)
Return the first node to fail when checking that a specified $node and its immediate children (if any) conform to the Dita standard else return undef if no failing node was found.
Parameter Description
1 $node Node in a L<Data::Edit::Xml|https://metacpan.org/pod/Data::Edit::Xml> parse tree
Example:
if (1)
{my $x = Data::Edit::Xml::new(<<END);
<concept>
<title>aaa</title>
<conbody>
<p>aaa</p>
<p><ol><li/><LI/><li/></ol></p>
<q>ccc</q>
<p>ddd</p>
</conbody>
</concept>
END
ok 3 == validateChild($x);
ok 3 == validateChild($x->go_title);
ok 3 == validateChild($x->go_conbody);
ok 3 == validateChild($x->go_conbody_p);
ok 3 == validateChild($x->go_conbody_p_1);
ok 2 == validateChild($x->go_conbody_q);
ok 1 == validateChild($x->go_conbody_p_2);
ok 3 == validateChild($x->go_conbody_p_1_ol_li);
ok 2 == validateChild($x->go_conbody_p_1_ol_LI);
ok 1 == validateChild($x->go_conbody_p_1_ol_li_1);
my $ol = $x->go_conbody_p_1_ol;
my $LI = $x->go_conbody_p_1_ol_LI;
ok $LI == 𝗳𝗶𝗿𝘀𝘁𝗙𝗮𝗶𝗹𝘂𝗿𝗲($ol);
ok $LI == 𝗳𝗶𝗿𝘀𝘁𝗙𝗮𝗶𝗹𝘂𝗿𝗲($LI);
}
This is a static method and so should be invoked as:
Dita::Validate::firstFailure
Private Methods
dfas()
Create a new set of Dita XML validation DFAs. Each Data::DFA below has been dumped, zipped, then converted to base 64 for convenient storage.
unpackDFA($)
Unpack the DFA required to check the parent
Parameter Description
1 $parent Parent node
Index
1 dfas - Create a new set of Dita XML validation DFAs.
2 firstFailure - Return the first node to fail when checking that a specified $node and its immediate children (if any) conform to the Dita standard else return undef if no failing node was found.
3 unpackDFA - Unpack the DFA required to check the parent
4 validateChild - Confirm that the given child node is both reachable and allowed in its current position.
Installation
This module is written in 100% Pure Perl and, thus, it is easy to read, comprehend, use, modify and install via cpan:
sudo cpan install Dita::Validate
Author
Copyright
Copyright (c) 2016-2019 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.