NAME
Tk::Tree::XML - XML tree widget
SYNOPSIS
use Tk::Tree::XML;
$top = MainWindow->new;
$xml_tree = $top->XML(?options?);
$xml_tree = $top->ScrolledXML(?options?);
$xml_tree->load_xml_file("file.xml");
$xml_tree->load_xml_string('<root><child /></root>');
DESCRIPTION
XML graphically displays the tree structure of XML documents loaded from either an XML file or an XML string.
XML enables Perl/Tk applications with a widget that allows visual representation and interaction with XML document trees.
Target applications may include XML viewers, editors and the like.
STANDARD OPTIONS
XML is a subclass of Tk::Tree and therefore inherits all of its standard options.
Details on standard widget options can be found at Tk::options.
WIDGET-SPECIFIC OPTIONS
- Name: pcdataMaxLength
- Class: PCDATAMaxLength
- Switch: -pcdatamaxlength
-
Set the maximum number of characters to be displayed for PCDATA elements. Content of such elements is trimmed to a length of pcdataMaxLength characters.
Default value:
80
. - Name: pcdataLongSymbol
- Class: PCDATALongSymbol
- Switch: -pcdatalongsymbol
-
Set the symbol to append to PCDATA content with length greater than pcdataMaxLength characters.
Default value:
...
. - Name: pcdataPreserveSpace
- Class: PCDATAPreserveSpace
- Switch: -pcdatapreservespace
-
Specify whether space characters surrounding PCDATA elements should be preserved or not. Such characters are preserved if this option is set to 1 and not preserved if set to 0.
Default value: 0.
WIDGET METHODS
The XML method creates a widget object. This object supports the configure and cget methods described in Tk::options which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic Tk::Widget class.
An XML is not scrolled by default. The ScrolledXML method creates a scrolled XML.
The following additional methods are available for XML widgets:
- $xml_tree->load_xml_file($xml_filename)
-
Load an XML document from a file into the tree. If the tree is already loaded with an XML document, no reloading occurs and a warning message is issued.
Return value: none.
Example(s):
# load XML document from file document.xml into the tree $xml_tree->load_xml_file('document.xml');
- $xml_tree->load_xml_string($xml_string)
-
Load an XML document represented by a string into the tree. If the tree is already loaded with an XML document, no reloading occurs and a warning message is issued.
Return value: none.
Example(s):
# load XML document from xml string into the tree $xml_tree->load_xml_string('<root><child /></root>');
- $xml_tree->get_name()
-
Retrieve the name of the currently selected XML element.
Return value: name of selected element if it is mixed, undef if it is PCDATA.
Example(s):
# retrieve name of currently selected element $element_name = $xml_tree->get_name();
- $xml_tree->get_attrs()
-
Retrieve the attribute list of the currently selected XML element.
Return value: attributes of selected element if it is mixed, undef if it is PCDATA. Attributes are returned as an associative array, where each key/value pair represent an attribute name/value, respectively.
Example(s):
# retrieve attribute list of currently selected element %attributes = $xml_tree->get_attrs();
- $xml_tree->get_text()
-
Retrieve the content of the currently selected XML element.
Return value: Text content if selected element is PCDATA, undef if it is mixed.
Example(s):
# retrieve content text of currently selected element $text = $xml_tree->get_text();
- $xml_tree->is_mixed()
-
Indicate whether the currently selected element is mixed or not. If the element is not mixed then it is PCDATA.
Return value: TRUE if the currently selected element is mixed, FALSE if it is PCDATA.
Example(s):
# determine if selected element is mixed or not print "element is " . ($xml_tree->is_mixed() ? 'mixed' : 'PCDATA');
- $xml_tree->is_pcdata()
-
Indicate whether the currently selected element is PCDATA or not. If the element is not PCDATA then it is mixed.
Return value: TRUE if the currently selected element is PCDATA, FALSE if it is mixed.
Example(s):
# determine if selected element is PCDATA or not print "element is " . ($xml_tree->is_pcdata() ? 'PCDATA' : 'mixed');
EXAMPLES
An XML viewer using Tk::Tree::XML can be found in the examples directory included with this module.
VERSION
Tk::Tree::XML version 0.01.
AUTHOR
Santos, José.
BUGS
Please report any bugs or feature requests to bug-tk-tree-xml at rt.cpan.org
or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-Tree-XML. The author will be notified and there will be automatic notification about progress on bugs as changes are made.
SUPPORT
Documentation for this module can be found with the following perldoc command:
perldoc Tk::Tree::XML
Additional information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT AND LICENSE
Copyright (c) 2008 José Santos. All rights reserved.
This program is free software. It can redistributed and/or modified under the same terms as Perl itself.
ACKNOWLEDGEMENTS
Thanks to Cotonete, Droit, Pistacho and Barriguita.
DEDICATION
I dedicate Tk::Tree::XML to my GrandMother.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 380:
Non-ASCII character seen before =encoding in 'José.'. Assuming CP1252