Hello Monks,

I need to grouping heading and its content. I got output by simple regex find and replace. But I need to do it using XML::Twig.

My input is

<root> <ahead>first head</ahead> <x>som text</x> <s>some text</s> <b>some text</b> <k>some text</k> <ahead>first head</ahead> <s>some text</s> <b>some text</b> <k>some text</k> <j>some text</j> </root>

Output

<root> <aheadtext> <ahead>first head</ahead> <x>som text</x> <s>some text</s> <b>some text</b> <k>some text</k> </aheadtext> <aheadtext> <ahead>second head</ahead> <s>some text</s> <b>some text</b> <k>some text</k> <j>some text</j> </aheadtext> </root>
I got the sibling nodes by following code
$t->parse($content); @sib = $t->get_xpath('//ahead', 0)->next_siblings();

I got all siblings in @sib including second ahead and its data. How to add the condition in next_siblings() to get the first ahead contents only?

Thanks,

Aakikce


In reply to XML::Twig - extracting some tags from siblings by aakikce

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.