[ejabberd] Help on XML parse

Kaiduan Xie kaiduanx at gmail.com
Sun Mar 15 17:08:48 MSK 2009


Thank you, Mickael for quick answer.

I think this is expat's feature, I also wrote a small test program in c, and
the behaviour is same. If I want to reuse the same parser, I need to call
XML_ParserReset, and set all the handlers.

kaiduan

On Sun, Mar 15, 2009 at 4:40 AM, Mickaël Rémond <
mickael.remond at process-one.net> wrote:

> Hello,
>
>  Successive parse steps consider it is the same document. You can have
> only one root XML element in an XML document.
> Note that ejabberd parser is build to parse XMPP and some of the features
> are XMPP oriented (not general XML).
>
>  On Sat, 14 Mar 2009 23:25 -0400, "Kaiduan Xie" <kaiduanx at gmail.com>
> wrote:
>
>
> Hi all,
>
> Driven by the interest in Erlang, I started digging into Ejabberd source
> code (Learning the best open source Erlang project is a good way to get
> familiar with Erlang). I got a problem on XML parsing. What I did was
> copying the expat_er.so, and modifying the xml_stream.erl,
>
> kaiduanx at kaiduanx-desktop:~/learn-erl/xml$ ls
> expat_erl.c  expat_erl.so  Makefile  xml_stream.beam  xml_stream.erl
> kaiduanx at kaiduanx-desktop:~/learn-erl/xml$ erl
> Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe]
> [kernel-poll:false]
>
> Eshell V5.6.5  (abort with ^G)
> 1> xml_stream:load().
> ok
> 2> Port = xml_stream:new().
> #Port<0.411>
> 3> xml_stream:parse(Port, "<people>Terry</people>").
> xml_stream_parse: [{0,{"people",[]}},{2,<<"Terry">>},{1,"people"}]
> <<131,108,0,0,0,1,104,2,97,0,104,2,107,0,6,112,101,111,
>   112,108,101,106,108,0,0,0,1,104,2,...>>
> 4> xml_stream:parse(Port, "<people>Terry</people>").
> xml_stream_parse: [{3,{9,"junk after document element"}}]
> <<131,108,0,0,0,1,104,2,97,3,104,2,97,9,107,0,27,106,117,
>   110,107,32,97,102,116,101,114,32,100,...>>
> 5>
>
> kaiduanx at kaiduanx-desktop:~/learn-erl/xml$ more xml_stream.erl
> -module(xml_stream).
>
> -export([load/0,
>          new/0,
>          parse/2,
>          close/1]).
>
> -define(XML_START, 0).
> -define(XML_END,   1).
> -define(XML_CDATA, 2).
> -define(XML_ERROR, 3).
>
> -define(PARSE_COMMAND, 0).
> -define(PARSE_FINAL_COMMAND, 1).
>
> load() ->
>    case erl_ddll:load_driver(".", "expat_erl") of
>        ok -> ok;
>        {error, already_loaded} -> ok;
>        _ -> exit({error, couldnot_load_driver})
>    end.
>
> new() ->
>     open_port({spawn, expat_erl}, [binary]).
>
> parse(Port, Str) ->
>     Res = port_control(Port, ?PARSE_COMMAND, Str),
>     io:format("xml_stream_parse: ~p~n", [binary_to_term(Res)]),
>     Res.
>
> close(Port) ->
>     port_close(Port).
>
> The problem is: why expat said "junk after document element"? The first
> parse succeeded.
>
>
>
>
> Thanks for help,
>
> kaiduan
>
> --
>   Mickaël Rémond
>   mickael.remond at process-one.net
>
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20090315/44c0a88a/attachment.htm>


More information about the ejabberd mailing list