Author image Reliance Technology Consultants, Inc.


Parse::Any2xml - Parse text into XML


  use Parse::Any2xml;
  $ximple_tree = parse( $xtmpl, $text );


Uses a template to make formatted, poorly formatted, or unformatted text into well-formed XML.


parse: <xtmpl> String -> <ximple_tree> Use the XML template to parse the string and return the resultant XML.


You should code at least one element within the root element. Whether to use elements or attributes is your choice. To code attributes use the _set_foo directive discussed below. Any attribute you code without the _set prefix is passed through by Parse::Any2xml.

All Any2XML directives are prefixed with a _ . Your attributes can start with an underscore, provided they do not clash with the defined directives.

Parse::Any2xml attributes

_match - Pattern match and extract

_match is an optional tag. By default "(.*)" is its value. It specifies a regular expression including memory and any inline switches.

Thus <newelement _set="$6" _set_abcd="$1*25"_fill="1"/> is same as <newelement _set="$6" _match="(.*)" _set_abcd="$1*25"_fill="1"/>

Unlike Perl's maximum of 9 memory variables ($1 .. $9), here you have unlimited memory variables, i.e. you can have $15, $20 etc. according to your match expression.

Example: _match="(?is)name:\s*(.*?)\n\s*address:\s*(.*?)\n"

_set - Source for Match

Sets the source that needs to be parsed (or further evaluated) according to the _match directive. This value is usually a matched memory value from a previous higher level match.

Note that its value is a valid Perl expression to be evaluated using eval().

Example: _set="$1.'-'.$2"

_set_foo - set Attribute foo

Allows creation of attribute with the name 'foo'.

Example: _set_amount="$3+$4-$5"

_exp - Perl expression

This sets the contents of an element if and only if _fill is used; it is ignored if _fill is not used. The contents of the element will be the result of this Perl expression.

_fill - Fill Element

Fill the current element using _exp if it exists, otherwise _set . Without this Parse::Any2xml will create an empty element. Using _fill destroys data such that an element's child will not be able to match on it.

 Example 1: <address _set="$4" _fill="1">
 Example 2: <company _set="$2" _set_name="$1" _exp="'Got'.$1.'Hooray'" _fill="1">
_debug-level - Print debugging/verbosity

Accepts a level number that ranges from 0 to 63, printing lots of information each time. The number is actually a bitwise number, much like chmod takes for permissions, so take any from the following table and add them together for your desired level of debugging.

0 - Nothing.
1 - Non-textual children (elements).
2 - Useful attributes.
4 - Regexes.
8 - Input text that is being matched on.
16 - Perl.
32 - Textual children (content).
Double-quoted Expressions

All values specified in double quotes for _match, _set, and _exp are eval()ed as Perl code. So any legal Perl code is allowed in here. So if you code any literals, you need to code them within single quotes and concatenate with any expressions used. Perl's rules in escaping special characters apply here. If the return value is a null or numeric or character zero, the value returned is null (i.e. ""). If you want to see a space or zero instead, concatenate a space or zero in front of the result.


Mailing List


Web site



  Reliance Technology Consultants, Inc. <>
  (Mike MacHenry <>)



2 POD Errors

The following errors were encountered while parsing the POD:

Around line 288:

'=item' outside of any '=over'

Around line 323:

You forgot a '=back' before '=head1'