.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .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" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" 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 "Template::Plugin::XML::DOM 3pm" .TH Template::Plugin::XML::DOM 3pm "2008-03-01" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Template::Plugin::XML::DOM \- Plugin interface to XML::DOM .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # load plugin \& [% USE dom = XML.DOM %] .Ve .PP .Vb 2 \& # also provide XML::Parser options \& [% USE dom = XML.DOM(ProtocolEncoding = \(aqISO\-8859\-1\(aq) %] .Ve .PP .Vb 3 \& # parse an XML file \& [% doc = dom.parse(filename) %] \& [% doc = dom.parse(file = filename) %] .Ve .PP .Vb 3 \& # parse XML text \& [% doc = dom.parse(xmltext) %] \& [% doc = dom.parse(text = xmltext) %] .Ve .PP .Vb 4 \& # call any XML::DOM methods on document/element nodes \& [% FOREACH node = doc.getElementsByTagName(\(aqreport\(aq) %] \& * [% node.getAttribute(\(aqtitle\(aq) %] # or [% node.title %] \& [% END %] .Ve .PP .Vb 6 \& # define VIEW to present node(s) \& [% VIEW report notfound=\(aqxmlstring\(aq %] \& # handler block for a ... element \& [% BLOCK report %] \& [% item.content(view) %] \& [% END %] .Ve .PP .Vb 5 \& # handler block for a
...
element \& [% BLOCK section %] \&

[% item.title %]

\& [% item.content(view) %] \& [% END %] .Ve .PP .Vb 2 \& # default template block converts item to string \& [% BLOCK xmlstring; item.toString; END %] .Ve .PP .Vb 3 \& # block to generate simple text \& [% BLOCK text; item; END %] \& [% END %] .Ve .PP .Vb 2 \& # now present node (and children) via view \& [% report.print(node) %] .Ve .PP .Vb 2 \& # or print node content via view \& [% node.content(report) %] .Ve .PP .Vb 4 \& # following methods are soon to be deprecated in favour of views \& [% node.toTemplate %] \& [% node.childrenToTemplate %] \& [% node.allChildrenToTemplate %] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a Template Toolkit plugin interfacing to the \s-1XML::DOM\s0 module. The plugin loads the \s-1XML::DOM\s0 module and creates an XML::DOM::Parser object which is stored internally. The \fIparse()\fR method can then be called on the plugin to parse an \s-1XML\s0 stream into a \s-1DOM\s0 document. .PP .Vb 2 \& [% USE dom = XML.DOM %] \& [% doc = dom.parse(\(aq/tmp/myxmlfile\(aq) %] .Ve .PP The \s-1XML::DOM\s0 plugin object (i.e. 'dom' in these examples) acts as a sentinel for the documents it creates ('doc' and any others). When the plugin object goes out of scope at the end of the current template, it will automatically call \fIdispose()\fR on any documents that it has created. Note that if you dispose of the the plugin object before the end of the block (i.e. by assigning a new value to the \&'dom' variable) then the documents will also be disposed at that point and should not be used thereafter. .PP .Vb 4 \& [% USE dom = XML.DOM %] \& [% doc = dom.parse(\(aq/tmp/myfile\(aq) %] \& [% dom = \(aqnew value\(aq %] # releases XML.DOM plugin and calls \& # dispose() on \(aqdoc\(aq, so don\(aqt use it! .Ve .PP The plugin constructor will also accept configuration options destined for the XML::Parser object: .PP .Vb 1 \& [% USE dom = XML.DOM(ProtocolEncoding = \(aqISO\-8859\-1\(aq) %] .Ve .SH "METHODS" .IX Header "METHODS" .Sh "\fIparse()\fP" .IX Subsection "parse()" The \fIparse()\fR method accepts a positional parameter which contains a filename or \s-1XML\s0 string. It is assumed to be a filename unless it contains a < character. .PP .Vb 2 \& [% xmlfile = \(aq/tmp/foo.xml\(aq %] \& [% doc = dom.parse(xmlfile) %] .Ve .PP .Vb 7 \& [% xmltext = BLOCK %] \& \& \& ... \& \& [% END %] \& [% doc = dom.parse(xmltext) %] .Ve .PP The named parameters 'file' (or 'filename') and 'text' (or 'xml') can also be used: .PP .Vb 2 \& [% doc = dom.parse(file = xmlfile) %] \& [% doc = dom.parse(text = xmltext) %] .Ve .PP The \fIparse()\fR method returns an instance of the XML::DOM::Document object representing the parsed document in \s-1DOM\s0 form. You can then call any \&\s-1XML::DOM\s0 methods on the document node and other nodes that its methods may return. See \s-1XML::DOM\s0 for full details. .PP .Vb 3 \& [% FOREACH node = doc.getElementsByTagName(\(aqCODEBASE\(aq) %] \& * [% node.getAttribute(\(aqhref\(aq) %] \& [% END %] .Ve .PP This plugin also provides an \s-1AUTOLOAD\s0 method for XML::DOM::Node which calls \fIgetAttribute()\fR for any undefined methods. Thus, you can use the short form of .PP .Vb 1 \& [% node.attrib %] .Ve .PP in place of .PP .Vb 1 \& [% node.getAttribute(\(aqattrib\(aq) %] .Ve .SH "PRESENTING DOM NODES USING VIEWS" .IX Header "PRESENTING DOM NODES USING VIEWS" You can define a \s-1VIEW\s0 to present all or part of a \s-1DOM\s0 tree by automatically mapping elements onto templates. Consider a source document like the following: .PP .Vb 14 \& \&
\&

\& Blah blah. \&

\&

\&
\&
\& ... \&
\&
.Ve .PP We can load it up via the \s-1XML::DOM\s0 plugin and fetch the node for the element. .PP .Vb 4 \& [% USE dom = XML.DOM; \& doc = dom.parse(file = filename); \& report = doc.getElementsByTagName(\(aqreport\(aq) \& %] .Ve .PP We can then define a \s-1VIEW\s0 as follows to present this document fragment in a particular way. The Template::Manual::Views documentation contains further details on the \s-1VIEW\s0 directive and various configuration options it supports. .PP .Vb 5 \& [% VIEW report_view notfound=\(aqxmlstring\(aq %] \& # handler block for a ... element \& [% BLOCK report %] \& [% item.content(view) %] \& [% END %] .Ve .PP .Vb 5 \& # handler block for a
...
element \& [% BLOCK section %] \&

[% item.title %]

\& [% item.content(view) %] \& [% END %] .Ve .PP .Vb 2 \& # default template block converts item to string representation \& [% BLOCK xmlstring; item.toString; END %] .Ve .PP .Vb 3 \& # block to generate simple text \& [% BLOCK text; item; END %] \& [% END %] .Ve .PP Each \s-1BLOCK\s0 defined within the \s-1VIEW\s0 represents a presentation style for a particular element or elements. The current node is available via the \&'item' variable. Elements that contain other content can generate it according to the current view by calling [% item.content(view) %]. Elements that don't have a specific template defined are mapped to the \&'xmlstring' template via the 'notfound' parameter specified in the \s-1VIEW\s0 header. This replicates the node as an \s-1XML\s0 string, effectively allowing general \s-1XML/XHTML\s0 markup to be passed through unmodified. .PP To present the report node via the view, we simply call: .PP .Vb 1 \& [% report_view.print(report) %] .Ve .PP The output from the above example would look something like this: .PP .Vb 8 \&

Introduction

\&

\& Blah blah. \&

\&

.Ve .PP .Vb 2 \&

The Gory Details

\& ... .Ve .PP To print just the content of the report node (i.e. don't process the \&'report' template for the report node), you can call: .PP .Vb 1 \& [% report.content(report_view) %] .Ve .SH "AUTHORS" .IX Header "AUTHORS" This plugin module was written by Andy Wardley and Simon Matthews. .PP The \s-1XML::DOM\s0 module is by Enno Derksen and Clark Cooper. It extends the the XML::Parser module, also by Clark Cooper which itself is built on James Clark's expat library. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2000\-2006 Andy Wardley, Simon Matthews. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" Template::Plugin, \s-1XML::DOM\s0, XML::Parser