Re: Xpath problem?
Liam Quin <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Oct 07, 2009 at 06:28:15PM +0200, Oliver Elphick wrote:
Well, nothing here :) but looking at the attchment, you need
to realise that the XPath expresion
./foo
is the same as
foo
and looks for an element child called foo at the current context.
That's child, not grand-child.
Given
<?xml version="1.0"?>
<shoe>
<sock>
<foot />
</sock>
</shoe>
then., at the document level,
//sock
will start at the top of the document and find all sock elements
./sock
will look and see a "shoe" child but no "sock" child.
So, change your ./ to .// or put in the full path...
Liam
--
Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin/
http://www.holoweb.net/~liam/ * http://www.fromoldbooks.org/
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
ol.pl
(application/x-perl, 2.4 KB)
#! /usr/bin/perl -w
use strict;
use warnings;
use XML::LibXML;
use XML::LibXML::XPathContext;
my $parser = XML::LibXML->new();
my $doc = $parser->parse_fh(\*DATA);
my $root = $doc->documentElement();
my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() );
$xc->registerNs(x => 'http://www.govtalk.gov.uk/CM/envelope');
my $class = $xc->findvalue( './x:MessageDetails/x:Class' );
my $qualifier = $xc->findvalue( './x:MessageDetails/x:Qualifier' );
my $transid = $xc->findvalue( './x:MessageDetails/x:TransactionID' );
my $timestamp = $xc->findvalue( './x:MessageDetails/x:GatewayTimestamp' );
my ($date, $time) = split 'T', $timestamp;
my $errno = $xc->findvalue( './x:Error/x:Number' );
my $errtp = $xc->findvalue( './x:Error/x:Type' );
my $errtxt = $xc->findvalue( './x:Error/x:Text' );
print qq~
Class : $class
Qualifier : $qualifier
TransactionID : $transid
Date : $date
Time : $time
Error number : $errno
Error type : $errtp
Error text : $errtxt
~;
exit(0);
__DATA__
<?xml version="1.0" encoding="UTF-8" ?>
<GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v1-0/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<EnvelopeVersion>1.0</EnvelopeVersion>
<Header>
<MessageDetails>
<Class>GetSubmissionStatus</Class>
<Qualifier>error</Qualifier>
<TransactionID>17980</TransactionID>
<GatewayTimestamp>2009-10-07T15:37:41-00:00</GatewayTimestamp>
</MessageDetails>
<SenderDetails>
<IDAuthentication>
<SenderID>783fc2a396ea93fae9dbb6ac36d645b0</SenderID>
<Authentication>
<Method>CHMD5</Method>
<Value></Value>
</Authentication>
</IDAuthentication>
<EmailAddress>[email protected]</EmailAddress>
</SenderDetails>
</Header>
<GovTalkDetails>
<Keys/>
<GovTalkErrors>
<Error>
<RaisedBy>GetSubmissionStatus</RaisedBy>
<Number>8026</Number>
<Type>fatal</Type>
<Text>X+0b4280-180990 Companies House are unable to complete this request (No Accepted or Rejected documents found in system. However, there could be documents we are currently processing in the system.) / 8026</Text>
<Location></Location>
</Error>
</GovTalkErrors>
</GovTalkDetails>
<Body>
</Body>
</GovTalkMessage>