Have a look at XML::LibXML::Iterator which, with a bit of trial and error, I got to produce your desired output:
use XML::LibXML; use XML::LibXML::Iterator; my $string = q|<?xml version="1.0"?> <PARTS> <TITLE>Computer Parts</TITLE> .... </PARTS>|; my $doc = XML::LibXML->new->parse_string( $string ); my $iterator = XML::LibXML::Iterator->new( $doc ); my ($path,$value) = ('',''); while ( $iterator->nextNode ) { if ($path and $value) { print "$path $value\n"; ($path,$value) = ('',''); } my $current = $iterator->current; my $type = $current->nodeType; if ( $type == XML_ELEMENT_NODE ) { $path = $current->nodePath; } elsif ( $type == XML_TEXT_NODE ) { my $text = $current->nodeValue; chomp $text; $value = $text if $text; } }
Output:
/PARTS/TITLE Computer Parts /PARTS/PART[1]/ITEM Motherboard /PARTS/PART[1]/MANUFACTURER ASUS /PARTS/PART[1]/MODEL P3B-F /PARTS/PART[1]/COST 123.00 /PARTS/PART[2]/ITEM Video Card /PARTS/PART[2]/MANUFACTURER ATI /PARTS/PART[2]/MODEL All-in-Wonder Pro /PARTS/PART[2]/COST 160.00 /PARTS/PART[3]/ITEM Sound Card /PARTS/PART[3]/MANUFACTURER Creative Labs /PARTS/PART[3]/MODEL Sound Blaster Live /PARTS/PART[3]/COST 80.00 /PARTS/PART[4]/ITEM inch Monitor /PARTS/PART[4]/MANUFACTURER LG Electronics /PARTS/PART[4]/MODEL 995E /PARTS/PART[4]/COST 290.00

In reply to Re: How can I browse & list XPATH of a XML Message? by tangent
in thread How can I browse & list XPATH of a XML Message? by MDRI

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.