f



XPATH - How to get rid of warnings or whats wrong!

Hello,
I have an Xpath expression:

//foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="'bla'"]

Here i check if i can find bla in  a foo tag - and its case
insensitive. If i use this expression I get warnings (failures?):

Unrecognized escape \Q passed through at (eval 4) line 1.
Unrecognized escape \E passed through at (eval 4) line 1.
Unrecognized escape \Q passed through at (eval 4) line 1.
Unrecognized escape \E passed through at (eval 4) line 1.

and I dont know what they mean?

if i check without the case sensitive test it works fine?

Does anyone know how to get rid of that warnings?

thx pod69

0
pod69 (12)
12/19/2006 1:12:53 PM
comp.lang.perl.misc 33233 articles. 2 followers. brian (1246) is leader. Post Follow

7 Replies
364 Views

Similar Articles

[PageSpeed] 8

In article <1166533973.278052.253170@80g2000cwy.googlegroups.com>,
<pod69@gmx.net> wrote:

> Hello,
> I have an Xpath expression:
> 
>
> //foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxy
> z")="'bla'"]
> 
> Here i check if i can find bla in  a foo tag - and its case
> insensitive. If i use this expression I get warnings (failures?):
> 
> Unrecognized escape \Q passed through at (eval 4) line 1.
> Unrecognized escape \E passed through at (eval 4) line 1.
> Unrecognized escape \Q passed through at (eval 4) line 1.
> Unrecognized escape \E passed through at (eval 4) line 1.
> 
> and I dont know what they mean?
> 
> if i check without the case sensitive test it works fine?
> 
> Does anyone know how to get rid of that warnings?

Please post a complete Perl program that demonstrates this problem.
Thanks.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com
0
Jim
12/19/2006 6:31:41 PM
Hello!

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

use XML::XPath;
use XML::XPath::XMLParser;

my $xml = do{ local $/; <DATA> };

my $xpath =
  XML::XPath->new(
$xml
  );
my $command =
'//foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="java"]';

my $nodeset = $xpath->find($command);
foreach my $node ( $nodeset->get_nodelist ) {
	my $t = XML::XPath::XMLParser::as_string($node)."\n";
	print $t;
}

__DATA__
<foo>Java</foo>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The output of this program is:

Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
1.
<foo>Java</foo>


thank you for your help!

0
pod69
12/20/2006 8:12:56 AM
<pod69@gmx.net> wrote in message 
news:1166602376.852110.245640@n67g2000cwd.googlegroups.com...
> Hello!
>
> #!/usr/bin/perl
>
> use XML::XPath;
> use XML::XPath::XMLParser;
>
> my $xml = do{ local $/; <DATA> };
>
> my $xpath =
>  XML::XPath->new(
> $xml
>  );
> my $command =
> '//foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="java"]';
>
> my $nodeset = $xpath->find($command);
> foreach my $node ( $nodeset->get_nodelist ) {
> my $t = XML::XPath::XMLParser::as_string($node)."\n";
> print $t;
> }
>
> __DATA__
> <foo>Java</foo>
>
> The output of this program is:
>
> Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
> 1.
> Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
> 1.
> Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
> 1.
> Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
> 1.
> <foo>Java</foo>

How about telling us what you are trying to do and what you expect the 
output to be?

If you are trying to lowercase the string, this seems to work:

$ cat xp2low.pl
use XML::XPath;

my $xml = do{ local $/; <DATA> };

my $xpath =  XML::XPath->new( $xml );
my $command = 
'translate(/foo,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")';

my $literal = $xpath->find($command);
print $literal->value, "\n";

__DATA__
<foo>Java</foo>

$ perl xp2low.pl
java

But it looks like you are trying to lowercase the string for the purpose of 
comparing it to a literal? XPath dosen't do that. That functionality is 
outside the scope of what XPath was designed to achieve. You need to use 
XPath in conjunction with XSLT if you are trying to do the entire operation 
inside of an xml processor.

Given that you haven't described to us what you want to do, Acme::ESP 
estimates the following is what you are looking for:

use XML::XPath;


my $xml = do{ local $/; <DATA> };

my $xpath =  XML::XPath->new( $xml );
my $command = 
'translate(/foo,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")';

my $value = $xpath->findvalue($command);
if ( $value eq 'java' ) {
  print "lowercasing the string results in [java]\n";
}

Though this would make more sense:

use XML::XPath;
use Data::Dumper;

my $xml = do{ local $/; <DATA> };

my $xpath =  XML::XPath->new( $xml );
my $command = '/foo';

my $value = $xpath->findvalue($command);
if ( lc $value eq 'java' ) {
  print "lowercasing the string results in [java]\n";
}

__DATA__
<foo>Java</foo>

Enjoy,

Todd W.


0
Todd
12/20/2006 12:18:54 PM
"Todd W" <trwww@sbcglobal.net> wrote in message 
news:OS9ih.35619$wP1.28537@newssvr14.news.prodigy.net...
>
> <pod69@gmx.net> wrote in message 
> news:1166602376.852110.245640@n67g2000cwd.googlegroups.com...
>> Hello!
>>
>> #!/usr/bin/perl
>>
>> use XML::XPath;
>> use XML::XPath::XMLParser;
>>
>> my $xml = do{ local $/; <DATA> };
>>
>> my $xpath =
>>  XML::XPath->new(
>> $xml
>>  );
>> my $command =
>> '//foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="java"]';
>>
>> my $nodeset = $xpath->find($command);
>> foreach my $node ( $nodeset->get_nodelist ) {
>> my $t = XML::XPath::XMLParser::as_string($node)."\n";
>> print $t;
>> }
>>
>> __DATA__
>> <foo>Java</foo>
>>
>> The output of this program is:
>>
>> Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
>> 1.
>> Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
>> 1.
>> Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
>> 1.
>> Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
>> 1.
>> <foo>Java</foo>
>
> How about telling us what you are trying to do and what you expect the 
> output to be?
>
<snip />
>
> ... it looks like you are trying to lowercase the string for the purpose 
> of comparing it to a literal? XPath dosen't do that. That functionality is 
> outside the scope of what XPath was designed to achieve. You need to use 
> XPath in conjunction with XSLT if you are trying to do the entire 
> operation inside of an xml processor.

Err, sorry, what you are doing is right, except for your (mis)use of 
XML::XPath::XMLParser::as_string. This seems to work fine:

use XML::XPath;

my $xml = do{ local $/; <DATA> };

my $xpath =  XML::XPath->new( $xml );
my $command = 
'//foo[translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="java"]';

my $nodeset = $xpath->find($command);
foreach my $node ( $nodeset->get_nodelist ) {
  print $node->toString, "\n";
}

__DATA__
<doc>
  <foo>Perl</foo>
  <foo>Java</foo>
  <foo>C++</foo>
</doc>

$ perl xp2low.pl
<foo>Java</foo>


0
Todd
12/20/2006 1:02:33 PM
Hello,

Thank you very much for your help. The program works fine but still the
output is:

Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 4) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 5) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 5) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 5) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 5) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 6) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 6) line 1, <DATA> line
1.
Unrecognized escape \Q passed through at (eval 6) line 1, <DATA> line
1.
Unrecognized escape \E passed through at (eval 6) line 1, <DATA> line
1.
<foo>Java</foo>

Use  #!/usr/bin/perl -w and you see all the warnings!

thx

0
pod69
12/20/2006 2:20:38 PM
<pod69@gmx.net> wrote in message 
news:1166624437.975852.321930@f1g2000cwa.googlegroups.com...
> Hello,
>
> Thank you very much for your help. The program works fine but still the
> output is:
>
> Unrecognized escape \Q passed through at (eval 4) line 1, <DATA> line
> 1.
>
<snip>
>
> <foo>Java</foo>
>
> Use  #!/usr/bin/perl -w and you see all the warnings!

Ah. A good reason to explain exactly what you are looking for when you post 
to usenet. I was helping you out with stuff you already had all figured out!

I see what you describe above. If I put "use warnings;" and remove the -w in 
the driver program, which gives the warnings pragma file scope instead of 
global scope, it runs without the warnings. -w is kind of rude in that it 
enables behavior in perl that a module author may not want. "use warnings" 
resolves that issue.

Todd W.


0
Todd
12/20/2006 2:44:42 PM
hello

thank you for your reply - i use eclipse as my IDE and maybe because of
that the behaviour is strange but i still get the warnings only if i
use the console i dont get them!

thank you

0
pod69
12/20/2006 3:27:26 PM
Reply: