The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::XPath::Helper::String - Helper functions for xpath expression.

VERSION

Version 1.00

SYNOPSIS

    use XML::LibXML;
    use XML::XPath::Helper::String qw(quoted_string one_of_quoted);

    my @nodes = $myXML->findnodes('subnode=' .
                                  quoted_string("value with '"));


    my @other_nodes =
      $myXML->findnodes('foo_node[' . one_of_quoted("bar_node",
                                                    "x'''y",
                                                    "z")
                                ']');

DESCRIPTION

This modules provides functions that helps building xpath expressions. The functions are exported on demand, you can use the :all tag to export all functions.

FUNCTIONS =over

quoted_string(ARG)

This function makes it easier to create xpath expressions seaching for values that contains single quotes. The problem with xpath is that it does not support an escape character, so you have to use a concat(...) in such cases. This function creates a concat(...) expression if needed.

ARG must be a string or a reference to an array of strings. If it is a string, the the function returns a string. If it is an array reference, then the function returns an array reference.

For each string in ARG the function does the following: if the string does not contain any single quote, then the result is the string enclosed in single quotes. So this

   print(quoted_string("hello"), "\n");

prints:

   'hello'

But this

   print(quoted_string("'this' that \"x\" '''"), "\n");

prints:

   concat("'",'this',"'",' that "x" ',"'''")
one_of_quoted(VALUES, NAME)
one_of_quoted(VALUES)

This function creates an xpath expressions checking if NAME contains one of the values in VALUES. It calls quoted_string to handle single quotes correctly. Example:

This

   print(one_of_quoted(["'a'", "b'''cd", "e"], "foo"), "\n");

prints

   foo=concat("'",'a',"'") or foo=concat('b',"'''",'cd') or foo='e'

If NAME is not specified, then the function returns a closure that takes one argument and produces the expression when called. Example:

This

   my $closure = one_of_quoted(["'a'", "b'''cd", "e"]);
   print($closure->("foo"), "\n",
         $closure->("bar"), "\n");

prints

   foo=concat("'",'a',"'") or foo=concat('b',"'''",'cd') or foo='e'
   bar=concat("'",'a',"'") or bar=concat('b',"'''",'cd') or bar='e'
not_one_of_quoted(VALUES, NAME)
not_one_of_quoted(VALUES)

Like one_of_quoted but creates an xpath expressions checking if NAME contains none of the values in VALUES. Example:

This:

   print(not_one_of_quoted("foo", "'a'", "b'''cd", "e"), "\n");

prints:

   foo!=concat("'",'a',"'") and foo!=concat('b',"'''",'cd') and foo!='e'

AUTHOR

Abdul al Hazred, <451 at gmx.eu>

BUGS

Please report any bugs or feature requests to bug-xml-xpath-helper-string at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-XPath-Helper-String. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc XML::XPath::Helper::String

You can also look for information at:

LICENSE AND COPYRIGHT

This software is copyright (c) 2022 by Abdul al Hazred.

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

SEE ALSO

XML::LibXML

1 POD Error

The following errors were encountered while parsing the POD:

Around line 124:

'=item' outside of any '=over'