You could try downloading one or more of the relevant module tar files from CPAN, and look at the source code to see how they do it.

You'll find that some (probably most) of them use a separate library package called "expat", which is written in C and is not part of CPAN (it is a toolkit for XML that is used in many non-Perl applications, as well as in Perl modules). The fact that the Perl XML parser modules depend on this "outside" resource causes pain for some people when they try to install these modules. But once you find the expat package, installing it is simple, and then installing the perl XML parser modules is also simple.

At the risk of leading you down a dangerous path, I would also point out that "XML data" can cover a broad range in terms of ease vs. difficulty for parsing. As a markup language, it can express very complex data structures as well as very simple ones.

If you need to process a set of XML data that you know has very simple structure, uses only a very limited range of XML expressions, and is fully predictable in terms of how the tags are rendered, then you could write a script that uses just regular expressions or string comparisons to handle such data, and not use a module.

But when you become familiar with the use of the XML modules, you will find that they typically allow you to write perl scripts that are shorter and easier to maintain and adapt. And of course, if and when you are faced with some really complex XML data, the appropriate XML module will be a life-saver.


In reply to Re: xml parsing without using cpan modules by graff
in thread xml parsing without using cpan modules by Nalina

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.