The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::DTD::ContentModel - Perl module representing an element content model in an XML DTD

SYNOPSIS

  use XML::DTD::ContentModel;

  my $cm = XML::DTD::ContentModel->new('(a,b*,(c|d)+)');
  print $cm->treestring;

DESCRIPTION

XML::DTD::ContentModel is a Perl module representing an element content model in an XML DTD. The following methods are provided.

new
 my $cm = XML::DTD::ContentModel->new('(a,b*,(c|d)+)');

Construct a new XML::DTD::ContentModel object.

isa
 if (XML::DTD::ContentModel->isa($obj) {
 ...
 }

Test object type.

children
 my $objlst = $cm->children;

Return an array of child objects (subexpressions) which are also of type XML::DTD::ContentModel.

 my $objlst = $cm->children($children);

Set the array of child objects (subexpressions). Returns the new value.

element
 my $name = $cm->element;

Return the element name if the object has no subexpressions.

 my $name = $cm->element($eltname);

Set the element name. The element name should only be set if the object has no subexpressions. Returns the new value.

combineop
 my $op = $cm->combineop;

Return the combination operator (",", "|" or undef).

 my $op = $cm->combineop($combineop);

Set the combination operator (",", "|", or undef). Returns the new value.

occurop
 my $op = $cm->occurop;

Return the occurrence operator ("?", "+", "*", or undef).

 my $op = $cm->occurop($occurop);

Set the occurrence operator ("?", "+", "*", or undef). Returns the new value.

isatomic
 if ($cm->isatomic) {
 ...
 }

Determine whether the object is atomic (i.e. the model consists of a single element, ANY, EMPTY, or #PCDATA).

childnames
 my $nmlst = $cm->childnames;

Return an array of contained element names as an array reference.

string
 print $cm->string;

Return a string representation of the content model.

treestring
 print $cm->treestring;

Return a string representing the hierarchical structure of the model.

writexmlelts
 open(FH,'>file.xml');
 my $xo = new XML::Output({'fh' => *FH});
 $cm->writexmlelts($xo);

Write a component-specific part of the XML representation.

type
 my $typstr = $cm->type;

Determine the content specification type ('empty', 'any', 'mixed', or 'element').

dfa
 my $dfa = $cm->dfa;

Construct a Deterministic Finite Automaton to validate the content model (returns an XML::DTD::Automaton object). The approach is to use Thompson's construction of an NDFA from a regular expression, and then convert to Glushkov form via epsilon state elimination. Since SGML/XML content models are constrained to be unambiguous (or deterministic), the resulting automaton should be deterministic. For background details see:

* Anne Brüggemann-Klein and Derick Wood, The Validation of SGML Content Models, Mathematical and Computer Modelling, 25, 73-84, 1997. ftp://ftp.informatik.uni-freiburg.de/documents/papers/brueggem/podpJournal.ps * Dora Giammarresi, Jean-Luc Ponty, and Derick Wood, Glushkov and Thompson Constructions: A Synthesis. Tech. Report 98-17. Università Ca' Foscari di Venezia. http://www.mat.uniroma2.it/~giammarr/Research/Papers/gluth.ps.Z

SEE ALSO

XML::DTD, XML::DTD::Element, XML::DTD::Automaton

AUTHOR

Brendt Wohlberg <wohl@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2006-2010 by Brendt Wohlberg

This library is available under the terms of the GNU General Public License (GPL), described in the GPL file included in this distribution.

ACKNOWLEDGMENTS

Peter Lamb <Peter.Lamb@csiro.au> fixed a bug in the _parse function, provided an improved implementation of _parenmatch, and modified accessor methods to allow setting of relevant values.