Hi all,<br><br>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,<br>
<br>kaiduanx@kaiduanx-desktop:~/learn-erl/xml$ ls<br>expat_erl.c  expat_erl.so  Makefile  xml_stream.beam  xml_stream.erl<br>kaiduanx@kaiduanx-desktop:~/learn-erl/xml$ erl<br>Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe] [kernel-poll:false]<br>
<br>Eshell V5.6.5  (abort with ^G)<br>1&gt; xml_stream:load().<br>ok<br>2&gt; Port = xml_stream:new().<br>#Port&lt;0.411&gt;<br>3&gt; xml_stream:parse(Port, &quot;&lt;people&gt;Terry&lt;/people&gt;&quot;).<br>xml_stream_parse: [{0,{&quot;people&quot;,[]}},{2,&lt;&lt;&quot;Terry&quot;&gt;&gt;},{1,&quot;people&quot;}]<br>
&lt;&lt;131,108,0,0,0,1,104,2,97,0,104,2,107,0,6,112,101,111,<br>  112,108,101,106,108,0,0,0,1,104,2,...&gt;&gt;<br>4&gt; xml_stream:parse(Port, &quot;&lt;people&gt;Terry&lt;/people&gt;&quot;).<br>xml_stream_parse: [{3,{9,&quot;junk after document element&quot;}}]<br>
&lt;&lt;131,108,0,0,0,1,104,2,97,3,104,2,97,9,107,0,27,106,117,<br>  110,107,32,97,102,116,101,114,32,100,...&gt;&gt;<br>5&gt; <br><br>kaiduanx@kaiduanx-desktop:~/learn-erl/xml$ more xml_stream.erl <br>-module(xml_stream).<br>
<br>-export([load/0,<br>         new/0,<br>         parse/2,<br>         close/1]).<br><br>-define(XML_START, 0).<br>-define(XML_END,   1).<br>-define(XML_CDATA, 2).<br>-define(XML_ERROR, 3).<br><br>-define(PARSE_COMMAND, 0).<br>
-define(PARSE_FINAL_COMMAND, 1).<br><br>load() -&gt;<br>   case erl_ddll:load_driver(&quot;.&quot;, &quot;expat_erl&quot;) of<br>       ok -&gt; ok;<br>       {error, already_loaded} -&gt; ok;<br>       _ -&gt; exit({error, couldnot_load_driver})<br>
   end.<br> <br>new() -&gt;<br>    open_port({spawn, expat_erl}, [binary]).<br><br>parse(Port, Str) -&gt;<br>    Res = port_control(Port, ?PARSE_COMMAND, Str),<br>    io:format(&quot;xml_stream_parse: ~p~n&quot;, [binary_to_term(Res)]),<br>
    Res.<br><br>close(Port) -&gt;<br>    port_close(Port).<br><br>The problem is: why expat said &quot;junk after document element&quot;? The first parse succeeded.<br><br>Thanks for help,<br><br>kaiduan<br>