Xpath problem?

Oliver Elphick <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <1254932895.15931.85.camel@cerberus>
In the attached piece of code, I cannot find any xpath specification
which will actually find anything out of the document.  Please let me
know what I am doing wrong.

(Incidentally, the XML received is coming from a government department.
If there is anything wrong with it, I cannot change it.)


Thanks
Oliver

_______________________________________________
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>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.