OK, I guess it's time to put on my XML-Ayatollah hat once again:

You have 2 choices here: if the data you want to process is really XML, then please, please, please, don't write your own parser but use either XML::SAX::PurePerl (a SAX parser) or XML::Parser::Lite (emulates XML::Parser, just check it thouroughly as it is used to parse SOAP messages in SOAP::Lite, which does not cover all of the XML spec). If the data is not XML (does it include & or < or HTML entities? Are tag names sometines not valid XML names, what about encoding, does it include some latin1 encoded accented characters?) then you can write your own parser (as an XML parser would complain and die) but then please, please, please don't call it XML. It will save you a huge amount of trouble when someone or something that expects XML tries using it.

XML is not the answer for everything. If this is an internal format then it's fine for it to be anything you want. But if you want to use XML then do it right from the start. It will pay off in the long run.

And remember that there are tools that can help you create valid XML, such as XML::Writer, or data bases XML export utilities.


In reply to Re: Parsing pseudo XML files by mirod
in thread Parsing pseudo XML files by BMaximus

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.