Template Toolkit: Модули: Template::Plugin::XML::XPath

Template Toolkit

(русская редакция)

[ Пособия ] [ Руководство ] [ Модули ] [ Библиотеки ] [ Утилиты ] [ Вопросы ] [ Релиз ] [ Perl-ресурсы ] Форум ]
 
Поиск
Template Toolkit | Модули | Template::Plugin::XML::XPath

Template::Plugin::XML::XPath

[ ◄ Template::Plugin::XML::Style ] [ Template::Plugin::Javascript ► ]
Plugin interface to XML::XPath

Оглавление

SYNOPSIS

Индекс ] [ Модули ] [ Наверх ]

    # load plugin and specify XML file to parse
    [% USE xpath = XML.XPath(xmlfile) %]
    [% USE xpath = XML.XPath(file => xmlfile) %]
    [% USE xpath = XML.XPath(filename => xmlfile) %]
    # load plugin and specify XML text to parse
    [% USE xpath = XML.XPath(xmltext) %]
    [% USE xpath = XML.XPath(xml => xmltext) %]
    [% USE xpath = XML.XPath(text => xmltext) %]
    # then call any XPath methods (see XML::XPath docs)
    [% FOREACH page = xpath.findnodes('/html/body/page') %]
       [% page.getAttribute('title') %]
    [% END %]
    # define VIEW to present node(s)
    [% VIEW repview notfound='xmlstring' %]
       # handler block for a <report>...</report> element
       [% BLOCK report %]
          [% item.content(view) %]
       [% END %]
       # handler block for a <section title="...">...</section> element
       [% BLOCK section %]
       <h1>[% item.getAttribute('title') | html %]</h1>
       [% item.content(view) %]
       [% END %]
       # default template block passes tags through and renders
       # out the children recursivly
       [% BLOCK xmlstring;
          item.starttag; item.content(view); item.endtag;
       END %]

       # block to generate simple text
       [% BLOCK text; item | html; END %]
    [% END %]
    # now present node (and children) via view
    [% repview.print(page) %]
    # or print node content via view
    [% page.content(repview) %]

PRE-REQUISITES

Индекс ] [ Модули ] [ Наверх ]

This plugin requires that the XML::Parser and XML::XPath modules be installed. These are available from CPAN:

    http://www.cpan.org/modules/by-module/XML

DESCRIPTION

Индекс ] [ Модули ] [ Наверх ]

This is a Template Toolkit plugin interfacing to the XML::XPath module.

All methods implemented by the XML::XPath modules are available. In addition, the XML::XPath::Node::Element module implements present($view) and content($view) methods method for seamless integration with Template Toolkit VIEWs. The XML::XPath::Node::Text module is also adorned with a present($view) method which presents itself via the view using the 'text' template.

To aid the reconstruction of XML, methods starttag and endtag are added to XML::XPath::Node::Element which return the start and end tag for that element. This means that you can easily do:

  [% item.starttag %][% item.content(view) %][% item.endtag %]

To render out the start tag, followed by the content rendered in the view "view", followed by the end tag.

AUTHORS

Индекс ] [ Модули ] [ Наверх ]

This plugin module was written by Andy Wardley <abw@wardley.org>.

The XML::XPath module is by Matt Sergeant <matt@sergeant.org>.

VERSION

Индекс ] [ Модули ] [ Наверх ]

2.70, distributed as part of the Template Toolkit version 2.14, released on 04 October 2004.

COPYRIGHT

Индекс ] [ Модули ] [ Наверх ]

  Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Индекс ] [ Модули ] [ Наверх ]