But here's a reason NOT to use regexp's for this task. Regular expressions work really well on "stuff" that doesn't require bouncing around. Even if you use regular expressions as part of the task, you'll wind up rescanning the same strings over and over again.
An actual parser will go from top down, doing all interpretation at best, once. XML is not a regular language, which a regular expression would work really well on. It's context-free, context meaning that things need to go in a certain order. In this case, things open and close in a particular order, like balanced parenthesis. If you used a regular expression, you may do a LOT of repeditive string scanning.
If you do decide to use a parser, which you probably will decide on, you have a choiec of DOM vs SAX. Dom parsers go over the document, and store everything in memory. For a fairly large document, this may take a long time and require a lot of memory.
A SAX parser would take away the convenience of doing an all-in-memory style parse, but require you to provide callbacks when tags open and close. This requires little memory, but much more involvement, such as when to start taking in data, when not to.. all based on when tags occur during parsing. After all...
Is quite legal.<xml-a> beedebeedebeede <xml-b> danger buck! </xml-b> beedebeedebeede </xml-a>
For tiny documents, unlimited memory slow parsing, DOM is great. For huge documents, speed or a lot of throw away data, SAX may be worth looking into.
In reply to XML Parsing, DOM, SAX and regexp.
by exussum0
in thread XML Parsing
by JoeJaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |