On 2/11/07, David Chisnall <[EMAIL PROTECTED]> wrote:
On 11 Feb 2007, at 20:17, Yen-Ju Chen wrote:
> Solely for partial XML parsing, does this help ?
> http://www.cs.queensu.ca/~thurston/ragel/
> It mentions Mongrel and Hpricot use it for HTML parsing.
> It is only used for generate codes, not a real dependency.
> I am also interested in using it for XML parsing or more general
> parsing.
The problem with XMPP is that they only time you have a complete XML
document is when you log off. Up to then, you have read an arbitrary
snapshot of a complete document. As such, you need to be able to
throw something like '<message><bod' at the parser and have it fire
off a start of tag 'message' event and then cache '<bod' and return.
Then, when you call it again with 'y>foo' fire off a start of tag
'body' event and a cdata 'foo' event.
It didn't look like Ragel could do that kind of thing, from reading
the description (correct me if I'm wrong). I also couldn't see what
it did above and beyond lex/yacc, which are found on all POSIX/SUS
systems.
Ragel help you write a XML parser.
It matches a string/regex and fire a function/method call you assigned.
So if a '<message><bod' is received,
you can matches '<message>' and fire call_message_tag()
and keep '<bod' in buffer for the next iteration.
If you have a home-made XML parser,
it basically replace the part where you need to match string
using strcmp or NSScanner.
Here is another description:
http://www.zedshaw.com/tips/ragel_state_charts.html
Just read the top introduction part.
The rest is not very useful in this discussion.
Yen-Ju
I suspect that the XMPP component will have different XML parsing
requirements to the rest of Étoilé. Ideally, we should have a single
interface to the parser(s), even if we use two different
implementations. As to XML generation, the TRXMLNode class might be
useful elsewhere; it allows XML trees to be constructed and then
turned into an NSString containing the XML. It wouldn't take much
tweaking to turn this into something a bit more DOM-like, which could
be useful in a lot of cases (it's bi-directional when used with my
XML parser; it implements the TRXMLParserDelegate protocol, so you
can use the parser to turn an NSString into an hierarchy of TRXMLNodes
[1]). Nodes can be created with a name and an NSDictionary
containing attributes, and child nodes / CDATA added to them.
David
[1] I used to do this as an intermediate step for creating XMPP
classes, but it added an extra layer of indirection for no good
reason, so I've stopped doing it now. I still use the TRXMLNode
class extensively for constructing XML for output, however.
_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev
_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev