I've got an XML file and need to parse out the measurements for a particular product. The measurement type is determined by <c093> tag (01- height 02-width 03-length 04-weight). I try to query it with this code but the Xpath query keeps saying "error in xpath expression" even though it works in my XML editor.
the code is:
use strict;
use XML::Twig;
use XML::XPath;
use XML::XPath::XMLParser;
my $twig= new XML::Twig( TwigHandlers => { product => \&product } );
+
$twig->parsefile("file.xml");
my @height = $twig->get_xpath ('//measure[string(c093)="01"]'); #if i
+ want to get the length
******************************************************
the xml file is:
<message>
<product>
<measure>
<c093>01</c093>
<c094>229.0</c094>
<c095>mm</c095>
</measure>
<measure>
<c093>02</c093>
<c094>152.0</c094>
<c095>mm</c095>
</measure>
<measure>
<c093>03</c093>
<c094>15.0</c094>
<c095>mm</c095>
</measure>
<measure>
<c093>08</c093>
<c094>24</c094>
<c095>oz</c095>
</measure>
</product>
20060311 Janitored by Corion: Added code tags around code and data
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.