Hi Monks!

I am trying to parse a simple XML file with the XML::Parser module. I use the Stream style as it seems more appropriate for my needs. I would like to make a graph out of some entries in the xml file, but I have a hard time parsing correctly the text of some entries. It seems that the Text subroutine is called a couple of times in the beginning AND in the end of each entry. Is there any way to control this behavior? Perhaps I haven't understood something about parsing XML's but it seems to me more reasonable to call the Text sub once for each entry in a consistent way (beginning OR end) which would make my code much simpler and easy.

Any recommendations on what to do?

The main part of the input file looks like:

<entry> this is the text I would like to parse</entry> <entry>more text <secondentry>interesting text</secondentry> </entry>
so I made a stack containing the innermost entry (adding in sub StartTag and removing when in EndTag) I was planning to add a list for pushing Text strings in it while in sub Text, but...I got stuck

Thanks!


In reply to confused with Stream style in XML::Parser by diamantis

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.