Are you trying to parse real XML, or just to build a tool that can handle some small subset of it? The reason I ask is that actual XML can contain a lot of oddities that your code above will not handle property. For instance, XML allows attribute-value pairs to have spaces around the equal sign, like this:
<Root id = "456990">
It looks like your code would choke on that, though. Unless you are absolutely sure that your input data, now and forever, will not contain anything but the ultra-strict subset of XML that your code will support, I would urge you to use XML::Parser. (I believe its internals are written in C, so it's actually quite fast; have you benchmarked it on your specific documents to see if it will meet your needs?)
I know you mentioned your criterion for efficiency is execution speed, and that you don't want to use a separate parser, so maybe I should just butt out. It's just that years of working with HTML and more recently XML have taught me to be extremely cautious. Building a parser that really respects the specs is a non-trivial task, and I'd hate to see fragile code go into production and then have to be torn out later for maintenance, when a perfectly good module is already available to do the task you intend.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.