|
NAMEXML::ValidWriter - DOCTYPE driven valid XML outputSYNOPSIS## As a normal perl object: $writer = XML::ValidWriter->new( DOCTYPE => $xml_doc_type, OUTPUT => \*FH ) ; $writer->startTag( 'b1' ) ; $writer->startTag( 'c2' ) ; $writer->end ; ## Writing to a scalar: $writer = XML::ValidWriter->new( DOCTYPE => $xml_doc_type, OUTPUT => \$buf ) ; ## Or, in scripting mode: use XML::Doctype NAME => a, SYSTEM_ID => 'a.dtd' ; use XML::ValidWriter qw( :all :dtd_tags ) ; b1 ; # Emits <a><b1> c2( attr=>"val" ) ; # Emits </b1><b2><c2 attr="val"> endAllTags ; # Emits </c2></b2></a> ## If you've got an XML::Doctype object handy: use XML::ValidWriter qw( :dtd_tags ), DOCTYPE => $doctype ; ## If you've saved a preparsed DTD as a perl module use FooML::Doctype::v1_0001 ; use XML::ValidWriter qw( :dtd_tags ) ; # # This all assumes that the DTD contains: # # <!ELEMENT a ( b1, b2?, b3* ) > # <!ATTLIST a aa1 CDATA #REQUIRED > # <!ELEMENT b1 ( c1 ) > # <!ELEMENT b2 ( c2 ) > # STATUSAlpha. Use and patch, don't depend on things not changing drastically.Many methods supplied by XML::Writer are not yet supplied here. DESCRIPTIONThis module uses the DTD contained in an XML::Doctype to enable compile- and run-time checks of XML output validity. It also provides methods and functions named after the elements mentioned in the DTD. If an XML::ValidWriter uses a DTD that mentions the element type TABLE, that instance will provide the methods$writer->TABLE( $content, ...attrs... ) ; $writer->start_TABLE( ...attrs... ) ; $writer->end_TABLE() ; $writer->empty_TABLE( ...attrs... ) ; . These are created for undeclared elements--those elements not explicitly declared with an <!ELEMENT ..> declaration--as well. If an element type name conflicts with a method, it will not override the internal method. When an XML::Doctype is parsed, the name of the doctype defines the root node of the document. This name can be changed, though, see XML::Doctype for details. In addition to the object-oriented API, a function API is also provided. This allows you to import most of the methods of XML::ValidWriter as functions using standard import specifications: use XML::ValidWriter qw( :all ) ; ## Could list function names instead ":all" does not import the functions named after elements mentioned in the DTD, you need to import those tags using ":dtd_tags": use XML::Doctype NAME => 'foo', SYSTEM_ID => 'fooml.dtd' ; use XML::ValidWriter qw( :all :dtd_tags ) ; or BEGIN { $doctype = XML::Doctype->new( ... ) ; } use XML::ValidWriter DOCTYPE => $doctype, qw( :all :dtd_tags ) ; XML::Writer API compatibilityMuch of the interface is patterned after XML::Writer so that it can possibly be used as a drop-in replacement. It will take awhile before this module emulates enough of XML::Writer to be a drop-in replacement in situations where the more advanced XML::Writer methods are used. If you find you need a method not suported here, write it and send it in!This was not derived from XML::Writer because XML::Writer does not expose it's stack. Even if it did, it's might be difficult to store enough state in it's stack. Unlike XML::Writer, this does not call in all of the IO::* family, and method dispatch should be faster. DTD-specific methods are also supported (see "AUTOLOAD"). Quick and Easy Unix Filter AppsFor quick applications that provide Unix filter application functionality, XML::ValidWriter and XML::Doctype cooperate to allow you to
OUTPUT OPTIMIZATIONXML is a very simple langauge and does not offer a lot of room for optimization. As the spec says "Terseness in XML markup is of minimal importance." XML::ValidWriter does optimize the following on output:"<a...></a>" becomes '<a... />' Spurious emissions of "]]><![CDATA[" are supressed. XML::ValidWriter chooses whether or not to use a <![CDATA[...]]> section or simply escape '<' and '&'. If you are emitting content for an element in multiple calls to "characters", the first call decides whether or not to use CDATA, so it's to your advantage to emit as much in the first call as possible. You can do characters( @lots_of_segments ) ; if it helps. METHODS AND FUNCTIONSAll of the routines in this module can be called as either functions or methods unless otherwise noted.To call these routines as functions use either the DOCTYPE or :dtd_tags options in the parameters to the use statement: use XML::ValidWriter DOCTYPE => XML::Doctype->new( ... ) ; use XML::ValidWriter qw( :dtd_tags ) ; This associates an XML::ValidWriter and an XML::Doctype with the package. These are used by the routines when called as functions.
NOTE: if you leave OUTPUT undefined, then the currently select()ed output is used at each emission (ie calling select() can alter the destination mid-stream). This eases writing command line filter applications, the select() interaction is unintentional, and please don't depend on it. I reserve the right to cache the select()ed filehandle at creation time or at time of first emission at some point in the future.
AUTHORBarrie Slaymaker <barries@slaysys.com>COPYRIGHTThis module is Copyright 2000, 2005 Barrie Slaymaker. All rights reserved.This module is licensed under your choice of the Artistic, BSD or General Public License.
Visit the GSP FreeBSD Man Page Interface. |