.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "XML::ValidWriter 3pm" .TH XML::ValidWriter 3pm "2014-09-17" "perl v5.20.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" XML::ValidWriter \- DOCTYPE driven valid XML output .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 8 \& ## As a normal perl object: \& $writer = XML::ValidWriter\->new( \& DOCTYPE => $xml_doc_type, \& OUTPUT => \e*FH \& ) ; \& $writer\->startTag( \*(Aqb1\*(Aq ) ; \& $writer\->startTag( \*(Aqc2\*(Aq ) ; \& $writer\->end ; \& \& ## Writing to a scalar: \& $writer = XML::ValidWriter\->new( \& DOCTYPE => $xml_doc_type, \& OUTPUT => \e$buf \& ) ; \& \& ## Or, in scripting mode: \& use XML::Doctype NAME => a, SYSTEM_ID => \*(Aqa.dtd\*(Aq ; \& use XML::ValidWriter qw( :all :dtd_tags ) ; \& b1 ; # Emits \& c2( attr=>"val" ) ; # Emits \& endAllTags ; # Emits \& \& ## If you\*(Aqve got an XML::Doctype object handy: \& use XML::ValidWriter qw( :dtd_tags ), DOCTYPE => $doctype ; \& \& ## If you\*(Aqve 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: \& # \& # \& # \& # \& # \& # .Ve .SH "STATUS" .IX Header "STATUS" Alpha. Use and patch, don't depend on things not changing drastically. .PP Many methods supplied by XML::Writer are not yet supplied here. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module uses the \s-1DTD\s0 contained in an XML::Doctype to enable compile\- and run-time checks of \s-1XML\s0 output validity. It also provides methods and functions named after the elements mentioned in the \s-1DTD. \s0 If an XML::ValidWriter uses a \s-1DTD\s0 that mentions the element type \s-1TABLE,\s0 that instance will provide the methods .PP .Vb 4 \& $writer\->TABLE( $content, ...attrs... ) ; \& $writer\->start_TABLE( ...attrs... ) ; \& $writer\->end_TABLE() ; \& $writer\->empty_TABLE( ...attrs... ) ; .Ve .PP \&. These are created for undeclared elements\*(--those elements not explicitly declared with an declaration\*(--as well. If an element type name conflicts with a method, it will not override the internal method. .PP 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. .PP In addition to the object-oriented \s-1API,\s0 a function \s-1API\s0 is also provided. This allows you to import most of the methods of XML::ValidWriter as functions using standard import specifications: .PP .Vb 1 \& use XML::ValidWriter qw( :all ) ; ## Could list function names instead .Ve .PP \&\f(CW\*(C`:all\*(C'\fR does not import the functions named after elements mentioned in the \s-1DTD,\s0 you need to import those tags using \f(CW\*(C`:dtd_tags\*(C'\fR: .PP .Vb 2 \& use XML::Doctype NAME => \*(Aqfoo\*(Aq, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; \& use XML::ValidWriter qw( :all :dtd_tags ) ; .Ve .PP or .PP .Vb 3 \& BEGIN { \& $doctype = XML::Doctype\->new( ... ) ; \& } \& \& use XML::ValidWriter DOCTYPE => $doctype, qw( :all :dtd_tags ) ; .Ve .SS "XML::Writer \s-1API\s0 compatibility" .IX Subsection "XML::Writer API compatibility" Much 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! .PP 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. .PP 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 \*(L"\s-1AUTOLOAD\*(R"\s0). .SS "Quick and Easy Unix Filter Apps" .IX Subsection "Quick and Easy Unix Filter Apps" For quick applications that provide Unix filter application functionality, XML::ValidWriter and XML::Doctype cooperate to allow you to .IP "1." 4 Parse a \s-1DTD\s0 at compile-time and set that as the default \s-1DTD\s0 for the current package. This is done using the .Sp .Vb 1 \& use XML::Doctype NAME => \*(AqFooML, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; .Ve .Sp syntax. .IP "2." 4 Define and export a set of functions corresponding to start and end tags for all declared and undeclared ELEMENTs in the \s-1DTD. \s0 This is done by using the \f(CW\*(C`:dtd_tags\*(C'\fR export symbol like so: .Sp .Vb 2 \& use XML::Doctype NAME => \*(AqFooML, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; \& use XML::ValidWriter qw(:dtd_tags) ; .Ve .Sp If the elements a, b_c, and d\-e are referred to in the \s-1DTD,\s0 the following functions will be exported: .Sp .Vb 3 \& a() end_a() # like startTag( \*(Aqa\*(Aq, ... ) and endTag( \*(Aqa\*(Aq ) \& b_c() end_b_c() \& d_e() end_d_e() {\*(Aqd\-e\*(Aq}() {\*(Aqend_d\-e\*(Aq}() .Ve .Sp These functions emit only tags, unlike the similar functions found in \s-1CGI\s0.pm and XML::Generator, which also allow you to pass content in as parameters. .Sp See below for details on conflict resolution in the mapping of entity names containing /\eW/ to Perl subroutine names. .Sp If the elements declared in the \s-1DTD\s0 might conflict with functions in your package namespace, simple put them in some safe namespace: .Sp .Vb 3 \& package FooML ; \& use XML::Doctype NAME => \*(AqFooML\*(Aq, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; \& use XML::ValidWriter qw(:dtd_tags) ; \& \& package Whatever ; .Ve .Sp The advantage of importing these subroutine names is that perl can then detect use of unknown tags at compile time. .Sp If you don't want to use the default \s-1DTD,\s0 use the \f(CW\*(C`\-dtd\*(C'\fR option: .Sp .Vb 2 \& BEGIN { $dtd = XML::Doctype\->new( .... ) } \& use XML::ValidWriter qw(:dtd_tags), \-dtd => \e$dtd ; .Ve .IP "3." 4 Use the default \s-1DTD\s0 to validate emitted \s-1XML. \s0 \fIstartTag()\fR and \fIendTag()\fR will check the tag being emitted against the list of currently open tags and either emit a minimal set of missing end and start tags necessary to achieve document validity or produce errors or warnings. .Sp Since the functions created by the \f(CW\*(C`:dtd_tags\*(C'\fR export symbol are wrappers around \fIstartTag()\fR and \fIendTag()\fR, they provide this functionality as well. .Sp So, if you have a \s-1DTD\s0 like .Sp .Vb 1 \& \& \& \& \& \& \& .Ve .Sp you can do this: .Sp .Vb 2 \& use XML::Doctype NAME => \*(Aqa\*(Aq, SYSTEM_ID => \*(Aqa.dtd\*(Aq ; \& use XML::ValidWriter \*(Aq:dtd_tags\*(Aq ; \& \& getDoctype\->element_decl(\*(Aqa\*(Aq)\->attdef(\*(Aqaa1\*(Aq)\->default_on_write(\*(Aqfoo\*(Aq) ; \& \& a ; \& b1 ; \& c1 ; \& end_c1 ; \& end_b1 ; \& b3 ; \& c3( \-attr => val ) ; \& end_c3 ; \& end_b3 ; \& end_a ; .Ve .Sp and emit a document like .Sp .Vb 8 \& \& \& \& \& \& "val" /> \& \& .Ve .Sp \&. .SH "OUTPUT OPTIMIZATION" .IX Header "OUTPUT OPTIMIZATION" \&\s-1XML\s0 is a very simple language and does not offer a lot of room for optimization. As the spec says \*(L"Terseness in \s-1XML\s0 markup is of minimal importance.\*(R" XML::ValidWriter does optimize the following on output: .PP \&\f(CW\*(C`\*(C'\fR becomes '' .PP Spurious emissions of \f(CW\*(C`]]> section or simply escape '<' and '&'. If you are emitting content for an element in multiple calls to \*(L"characters\*(R", the first call decides whether or not to use \&\s-1CDATA,\s0 so it's to your advantage to emit as much in the first call as possible. You can do .PP .Vb 1 \& characters( @lots_of_segments ) ; .Ve .PP if it helps. .SH "METHODS AND FUNCTIONS" .IX Header "METHODS AND FUNCTIONS" All of the routines in this module can be called as either functions or methods unless otherwise noted. .PP To call these routines as functions use either the \s-1DOCTYPE\s0 or :dtd_tags options in the parameters to the use statement: .PP .Vb 2 \& use XML::ValidWriter DOCTYPE => XML::Doctype\->new( ... ) ; \& use XML::ValidWriter qw( :dtd_tags ) ; .Ve .PP This associates an XML::ValidWriter and an XML::Doctype with the package. These are used by the routines when called as functions. .IP "new" 4 .IX Item "new" .Vb 1 \& $writer = XML::ValidWriter\->new( DTD => $dtd, OUTPUT => \e*FH ) ; .Ve .Sp Creates an XML::ValidWriter. .Sp The value passed for \s-1OUTPUT\s0 may be: .RS 4 .IP "a \s-1SCALAR\s0 ref" 4 .IX Item "a SCALAR ref" if you want to direct output to append to a scalar. This scalar is truncated whenever the XML::ValidWriter object is \fIreset()\fR or \&\s-1\fIDESTROY\s0()\fRed .IP "a file handle glob ref or a reference to an \s-1IO\s0 object" 4 .IX Item "a file handle glob ref or a reference to an IO object" XML::ValidWriter does not load \s-1IO. \s0 This is the only mode compatible with XML::Writer. .IP "a file name" 4 .IX Item "a file name" A simple scalar is taken to be a filename to be created or truncated and emitted to. This file will be closed when the XML::ValidWriter object is reset or deatroyed. .RE .RS 4 .Sp \&\s-1NOTE:\s0 if you leave \s-1OUTPUT\s0 undefined, then the currently \fIselect()\fRed output is used at each emission (ie calling \fIselect()\fR can alter the destination mid-stream). This eases writing command line filter applications, the \fIselect()\fR interaction is unintentional, and please don't depend on it. I reserve the right to cache the \fIselect()\fRed filehandle at creation time or at time of first emission at some point in the future. .RE .IP "import" 4 .IX Item "import" Can't think of why you'd call this method directly, it gets called when you use this module: .Sp .Vb 1 \& use XML::ValidWriter qw( :all ) ; .Ve .Sp In addition to the normal functionality of exporting functions like \&\fIstartTag()\fR and \fIendTag()\fR, XML::ValidWriter's \fIimport()\fR can create functions corresponding to all elements in a \s-1DTD. \s0 This is done using the special \f(CW\*(C`:dtd_tags\*(C'\fR export symbol. For example, .Sp .Vb 2 \& use XML::Doctype NAME => \*(AqFooML\*(Aq, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; \& use XML::ValidWriter qw( :dtd_tags ) ; .Ve .Sp where fooml.dtd referse to a tag type of 'blurb' causes these functions to be imported: .Sp .Vb 4 \& blurb() # calls defaultWriter\->startTag( \*(Aqblurb\*(Aq, @_ ) ; \& blurb_element() # calls defaultWriter\->dataElement( \*(Aqblurb\*(Aq, @_ ) ; \& empty_blurb() # calls defaultWriter\->emptyTag( \*(Aqblurb\*(Aq, @_ ) ; \& end_blurb() # calls defaultWriter\->endTag( \*(Aqblurb\*(Aq ) ; .Ve .Sp The range of characters for element types is much larger than the range of characters for bareword perl subroutine names, which are limited to [a\-zA\-Z0\-9_]. In this case, XML::ValidWriter will export an oddly named function that you can use a symbolic reference to call (you will need \f(CW\*(C`no strict \*(Aqrefs\*(Aq ;\*(C'\fR if you are doing a \f(CW\*(C`use strict ;\*(C'\fR): .Sp .Vb 1 \& &{"space\-1999:moonbase"}( ...attributes ... ) ; .Ve .Sp \&. XML::ValidWriter will also try to fold the name in to bareword space by converting /\eW/ symbols to '_'. If the resulting function name, .Sp .Vb 1 \& space_1999_moonbase( ...attributes... ) ; .Ve .Sp has not been generated and is not the name of an element type, then it will also be exported. .Sp If you are using a \s-1DTD\s0 that might introduce function names that conflict with existing ones, simple export them in to their own namespace: .Sp .Vb 1 \& package ML ; \& \& use XML::Doctype NAME => \*(Aqfoo\*(Aq, SYSTEM_ID => \*(Aqfooml.dtd\*(Aq ; \& use XML::ValidWriter qw( :dtd_tags ) ; \& \& package main ; \& \& use XML::ValidWriter qw( :all ) ; \& \& ML::foo ; \& ML::c2 ; \& ML::c1 ; \& ML::end_a ; .Ve .Sp I gave serious thought to converting ':' in element names to '::' in function declarations, which might work well in the functions\-in\-their\-own\- namespace case, but not in the default case, since Perl does not (yet) have relative namespaces. Another alternative is to allow a mapping of \s-1XML\s0 namespaces to Perl namespaces to be done. .IP "characters" 4 .IX Item "characters" .Vb 2 \& characters( "escaped text", "& more" ) ; \& $writer\->characters( "escaped text", "& more" ) ; .Ve .Sp Emits character data. Character data will be escaped before output, by either transforming '<' and '&' to < and &, or by enclosing in a \&'\f(CW\*(C`\*(C'\fR' bracket, depending on which will be more human-readable, according to the module. .IP "dataElement" 4 .IX Item "dataElement" .Vb 6 \& $writer\->dataElement( $tag ) ; \& $writer\->dataElement( $tag, $content ) ; \& $writer\->dataElement( $tag, $content, attr1 => $val1, ... ) ; \& dataElement( $tag ) ; \& dataElement( $tag, $content ) ; \& dataElement( $tag, $content, attr1 => $val1, ... ) ; .Ve .Sp Does the equivalent to .Sp .Vb 4 \& ## Split the optional args in to attributes and elements arrays. \& $writer\->startTag( $tag, @attributes ) ; \& $writer\->characters( $content ) ; \& $writer\->endTag( $tag ) ; .Ve .Sp This function is exportable as \fIdataElement()\fR, and is also exported for each element 'foo' found in the \s-1DTD\s0 as \fIfoo()\fR. .IP "defaultWriter" 4 .IX Item "defaultWriter" .Vb 2 \& $writer = defaultWriter ; ## Not a method! \& $writer = defaultWriter( \*(AqFoo::Bar\*(Aq ) ; .Ve .Sp Returns the default XML::ValidWriter for the given package, or the current package if none is specified. This is useful for getting at methods like \f(CW\*(C`reset\*(C'\fR that are not also functions. .Sp Croaks if no default writer has been defined (see \*(L"import\*(R"). .IP "doctype" 4 .IX Item "doctype" .Vb 2 \& # Using the writer\*(Aqs associated DTD: \& doctype ; \& \& # Ignoring the writer\*(Aqs associated DTD: \& doctype( $type ) ; \& doctype( $type, undef, $system ) ; \& doctype( $type, $public, $system ) ; \& \& $writer\->doctype ; \& ...etc .Ve .Sp See \*(L"internalDoctype\*(R" to emit the entire \s-1DTD\s0 in the document. .Sp This checks to make sure that no doctype or elements have been emitted. .Sp A warning is emitted if standalone=\*(L"yes\*(R" was specified in the declaration and a system id is specified. This is extremely likely to be an error. If you need to silence the warning, write me (see below). .Sp Passing '' or '0' (zero) as a \f(CW$public_id\fR or as a \f(CW$system_id\fR also generates a warning, as these are extremely likely to be errors. .IP "emptyTag" 4 .IX Item "emptyTag" .Vb 2 \& emptyTag( $tag[, attr1 => $val1... ] ) ; \& $writer\->emptyTag( $tag[, attr1 => $val1... ] ) ; .Ve .Sp Emits an empty tag like ''. The extra space is for compatibility with \s-1XHTML.\s0 .IP "endTag" 4 .IX Item "endTag" .Vb 4 \& endTag ; \& endTag( \*(Aqa\*(Aq ) ; \& $writer\->endTag ; \& $writer\->endTag( \*(Aqa\*(Aq ) ; .Ve .Sp Prints one or more end tags. The tag name is optional and defaults to the most recently emitted start tag if not present. .Sp This will emit as many close tags as necessary to close the supplied tag name, or will emit an error if the tag name specified is not open in the output document. .IP "end" 4 .IX Item "end" .Vb 1 \& $writer\->end ; # Not a function!! .Ve .Sp Emits all necessary end tags to close the document. Available as a method only, since 'end' is a little to generic to be exported as a function name, \s-1IMHO. \s0 See 'endAllTags' for the plain function equivalent function. .IP "endAllTags" 4 .IX Item "endAllTags" .Vb 2 \& endAllTags ; \& $writer\->endAllTags ; .Ve .Sp A plain function that emits all necessart end tags to close the document. Corresponds to the method \f(CW\*(C`end\*(C'\fR, but is exportable as a function/ .IP "exportDTDTags" 4 .IX Item "exportDTDTags" .Vb 2 \& $writer\->exportDTDTags() ; \& $writer\->exportDTDTags( $to_pkg ) ; .Ve .Sp Exports the tags found in the \s-1DTD\s0 to the caller's namespace. .IP "getDataMode" 4 .IX Item "getDataMode" .Vb 2 \& $m = getDataMode ; \& $m = $writer\->getDataMode ; .Ve .Sp Returns \s-1TRUE\s0 if the writer is in \s-1DATA_MODE.\s0 .IP "getDoctype" 4 .IX Item "getDoctype" .Vb 2 \& $dtd = getDoctype ; \& $dtd = $writer\->getDoctype ; .Ve .Sp This is used to get the writer's XML::Doctype object. .IP "getOutput" 4 .IX Item "getOutput" .Vb 2 \& $fh = getOutput ; \& $fh = $writer\->getOutput ; .Ve .Sp Gets the filehandle an XML::ValidWriter sends output to. .IP "rawCharacters" 4 .IX Item "rawCharacters" .Vb 2 \& rawCharacters( "", "& more text" ) ; \& $writer\->rawCharacters( "", "& more text" ) ; .Ve .Sp This allows you to emit raw text without any escape processing. The text is not examined for tags, so you can invalidate your document and even corrupt it's well-formedness. .IP "reset" 4 .IX Item "reset" .Vb 1 \& $writer\->reset ; # Not a function! .Ve .Sp Resets a writer to be initialized, but not have emitted anything. .Sp This is useful if you need to abort output, but want to reuse the XML::ValidWriter. .IP "setDataMode" 4 .IX Item "setDataMode" .Vb 2 \& setDataMode( 1 ) ; \& $writer\->setDataMode( 1 ) ; .Ve .Sp Enable or disable data mode. .IP "setDoctype" 4 .IX Item "setDoctype" .Vb 2 \& setDoctype $doctype ; \& $writer\->setDoctype( $doctype ) ; .Ve .Sp This is used to set the doctype object. .IP "select_xml" 4 .IX Item "select_xml" .Vb 1 \& select_xml OUTHANDLE ; # Nnot a method!! .Ve .Sp Selects a filehandle to send the \s-1XML\s0 output to when not using the object oriented interface. This is similar to perl's builtin select, but only affects startTag and endTag functions, (not methods). .Sp This is only needed if you want to interleave output to the selected output files (usually \s-1STDOUT,\s0 see \*(L"select\*(R" in perlfunc and to an \&\s-1XML\s0 file on another filehandle. .Sp If you want to redirect all output (yours and XML::Writer's) to the same file, just use Perl's built-in \fIselect()\fR, since startTag and endTag emit to the currently selected filehandle by default. .Sp Like select, this returns the old value. .IP "setOutput" 4 .IX Item "setOutput" .Vb 2 \& setOutput( \e*FH ) ; \& $writer\->setOutput( \e*FH ) ; .Ve .Sp Sets the filehandle an XML::ValidWriter sends output to. .IP "startTag" 4 .IX Item "startTag" .Vb 3 \& startTag( \*(Aqa\*(Aq, attr => val ) ; # use default XML::ValidWriter for \& # current package. \& $writer\->startTag( \*(Aqa\*(Aq, attr => val ) ; .Ve .Sp Emits a named start tag with optional attributes. If the named tag cannot be a child of the most recently started tag, then any tags that need to be opened between that one and the named tag are opened. .Sp If the named tag cannot be enclosed within the most recently opened tag, no matter how deep, then \fIstartTag()\fR tries to end as few started tags as necessary to allow the named tag to be emitted within a tag already on the stack. .Sp This warns (once) if no declaration has been emitted. It does not check to see if a has been emitted. It dies if an attempt is made to emit a second root element. .ie n .IP "xmlDecl([[$encoding][, $standalone])" 4 .el .IP "xmlDecl([[$encoding][, \f(CW$standalone\fR])" 4 .IX Item "xmlDecl([[$encoding][, $standalone])" .Vb 4 \& xmlDecl ; \& xmlDecl( "UTF\-8" ) ; \& xmlDecl( "UTF\-8", "yes" ) ; \& $writer\->xmlDecl( ... ) ; .Ve .Sp Emits an \s-1XML\s0 declaration. Must be called before any of the other output routines. .Sp If \f(CW$encoding\fR is not defined, it is not output. This is slightly different than XML::Writer, which outputs '\s-1UTF\-8\s0' if you pass in undef, 0, or ''. .Sp If \f(CW$encoding\fR is '' or 0, then it is output as "\*(L" or \*(R"0" and a warning is generated. .Sp If \f(CW$standalone\fR is defined and is not 'no', 0, or '', it is output as 'yes'. If it is 'no', then it is output as 'no'. If it's 0 or '' it is not output. .IP "\s-1AUTOLOAD\s0" 4 .IX Item "AUTOLOAD" This function is called whenever a function or method is not found in XML::ValidWriter. .Sp If it was a method being called, and the desired method name is a start or end tag found in the \s-1DTD,\s0 then a method is cooked up on the fly. .Sp These methods are slower than normal methods, but they are cached so that they don't need to be recompiled. The speed penalty is probably not significant since they do I/O and are thus usually orders of magnitude slower than normal Perl methods. .IP "\s-1DESTROY\s0" 4 .IX Item "DESTROY" \&\s-1DESTROY\s0 is called when an XML::ValidWriter is cleaned up. This is used to automatically close all tags that remain open. This will not work if you have closed the output filehandle that the ValidWriter was using. .Sp This method will also warn if anything was emitted bit no root node was emitted. This warning can be silenced by calling .Sp .Vb 1 \& $writer\->reset() ; .Ve .Sp when you abandon output. .SH "AUTHOR" .IX Header "AUTHOR" Barrie Slaymaker .SH "COPYRIGHT" .IX Header "COPYRIGHT" This module is Copyright 2000, 2005 Barrie Slaymaker. All rights reserved. .PP This module is licensed under your choice of the Artistic, \s-1BSD\s0 or General Public License.