Processing Excel XML files with Perl and LibXML

tsoglanos

New Member
I'm trying to process data in an Excel file saved as an XML spreadsheet. After doing a fair amount of research (I've not done much XML processing before) I still couldn't make it work. Here is the content of my minimal file:\[code\]<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:eek:ffice:spreadsheet" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:x="urn:schemas-microsoft-com:eek:ffice:excel" xmlns:ss="urn:schemas-microsoft-com:eek:ffice:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:sbmextension="http://www.serena.com/SBM/XSLT_Extension"> <Worksheet ss:Name="index"> </Worksheet></Workbook>\[/code\]And my script:\[code\]use XML::LibXML;use Data::Dumper;my $filename = $ARGV[0];my $parser = XML::LibXML->new();my $doc = $parser->parse_file($filename);my $xc = XML::LibXML::XPathContext->new( $doc->documentElement );my $xpath = '/Workbook/Worksheet/@ss:Name';print Dumper $xc->findvalue($xpath);\[/code\]However, if I remove (the default namespace?) xmlns="urn:schemas-microsoft-com:eek:ffice:spreadsheet" then it starts working. Please can you tell me what I'm missing? I guess I could just remove it before parsing the document but I would like to understand what I've done wrong :). Thanks in advance.
 
Top