NAME

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

VERSION

Version 0.01

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

quoted_string(STRING)

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.

If STRING does not contain any single quote, then the function returns 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(NAME, VALUES)

This functions takes two or more string arguments. NAME should be the name of an XML node. The function creates an xpath expressions checking if NAME contains one of the values in VALUES. It calls quoted_string if needed. Example:

This

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

prints

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

not_one_of_quoted(NAME, 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.