[erlang-questions] xmerl SAX interface

Willem de Jong w.a.de.jong@REDACTED
Mon Feb 5 19:55:59 CET 2007


Hello,

I tried to find this out as well, but I didn't find the answer either.
I ended up implementing my own SAX parser. It is part of Erlsom (which
you can find on Sourceforge).

Your example could be parsed as follows.

S = "<e1 xmlns='urn'>
      <e2 a2='b'>2</e2>
      <e3>3</e3>
     </e1>".

C = fun(Event, State) ->
  io:format("~p\n", [Event]),
  State
  end.

erlsom:sax(S, [], C).

The result:
startDocument
{startPrefixMapping,[],"urn"}
{startElement,"urn","e1",[],[]}
{ignorableWhitespace,"\n\n    "}
{startElement,"urn","e2",[],[{attribute,"a2","a2",[],"b"}]}
{characters,"2"}
{endElement,"urn","e2",[]}
{ignorableWhitespace,"\n\n    "}
{startElement,"urn","e3",[],[]}
{characters,"3"}
{endElement,"urn","e3",[]}
{ignorableWhitespace,"\n\n  "}
{endElement,"urn","e1",[]}
{endPrefixMapping,[]}
endDocument
[]

Regards,
Willem

On 2/5/07, Ladislav Lenart <lenartlad@REDACTED> wrote:
> Hello,
>
> I am trying to implement a XML SAX driver using xmerl and I got lost
> on the way a little. xmerl_eventp seems that it is what I am looking
> for (SAX driver), but when I try to parse the following
>
>   <e1 xmlns='urn'>
>     <e2 a2='b'>2</e2>
>     <e3>3</e3>
>   </e1>
>
> I get only the "closing" events which is not what I would expect
> (from a SAX driver).
>
> I have read the examples in xmerl 0.20 and used Google extensively,
> but with no luck so far.
>
> Can anyone please show me how to set up and SAX-parse a simple XML
> document like the one above (namespaces are not necessary but would
> be great, too).
>
> Links to xmerl tutorials/faqs/... are also welcome.
>
> Thanks in advance,
>
> Ladislav Lenart
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list