From: Bill Kelly Date: 2009-03-26T07:25:11+09:00 Subject: Re: Parsing xml From: "Jason Roelofs" > > Regex is not stateful, thus you can't use it to parse XML. Oh there > are ways to hack yourself around some limitations and get some > results, but you are going to spend a TON of time making very > unreadable Regex that will die at the presense of slightest malformed > XML. But, regexps work just fine to lex XML. The parser, then, becomes a bit of ruby that accepts tokens from the regexp lexer. Handling the most common syntactic elements of an XML doc this way (tags, text, cdata) is relatively trivial. On the other hand, as we can see from the BNF, handling the full XML spec is complicated: http://pastie.org/pastes/427101 . . . In any case, I'm fully on board with the "why reinvent the wheel?" replies in this thread. I just had to visit this territory recently because REXML doesn't work properly in a $SAFE = 4 sandbox. Regards, Bill