aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmerl/src/xmerl_sax_parser.erl
diff options
context:
space:
mode:
authorLars Thorsen <[email protected]>2014-01-16 12:21:20 +0100
committerMagnus Lidén <[email protected]>2014-01-21 16:38:28 +0100
commite750b2aa3698d5bd7f4a9d23f568031e34c6ba2a (patch)
tree57dbc03e9e25bbccc55335148615116a7e58c781 /lib/xmerl/src/xmerl_sax_parser.erl
parentfbcf11307e6e5eb9685fe6603ec2935638217423 (diff)
downloadotp-e750b2aa3698d5bd7f4a9d23f568031e34c6ba2a.tar.gz
otp-e750b2aa3698d5bd7f4a9d23f568031e34c6ba2a.tar.bz2
otp-e750b2aa3698d5bd7f4a9d23f568031e34c6ba2a.zip
[xmerl] Fix problem with header of next XML document is in the buffer
when using xmerl_sax_parser:stream/2 function.
Diffstat (limited to 'lib/xmerl/src/xmerl_sax_parser.erl')
-rw-r--r--lib/xmerl/src/xmerl_sax_parser.erl32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/xmerl/src/xmerl_sax_parser.erl b/lib/xmerl/src/xmerl_sax_parser.erl
index 5c006aada2..ad71072d95 100644
--- a/lib/xmerl/src/xmerl_sax_parser.erl
+++ b/lib/xmerl/src/xmerl_sax_parser.erl
@@ -74,7 +74,8 @@ file(Name,Options) ->
CL = filename:absname(Dir),
File = filename:basename(Name),
ContinuationFun = fun default_continuation_cb/1,
- Res = stream(<<>>, [{continuation_fun, ContinuationFun},
+ Res = stream(<<>>,
+ [{continuation_fun, ContinuationFun},
{continuation_state, FD},
{current_location, CL},
{entity, File}
@@ -98,9 +99,13 @@ stream(Xml, Options) when is_list(Xml), is_list(Options) ->
State = parse_options(Options, initial_state()),
case State#xmerl_sax_parser_state.file_type of
dtd ->
- xmerl_sax_parser_list:parse_dtd(Xml, State#xmerl_sax_parser_state{encoding = list});
+ xmerl_sax_parser_list:parse_dtd(Xml,
+ State#xmerl_sax_parser_state{encoding = list,
+ input_type = stream});
normal ->
- xmerl_sax_parser_list:parse(Xml, State#xmerl_sax_parser_state{encoding = list})
+ xmerl_sax_parser_list:parse(Xml,
+ State#xmerl_sax_parser_state{encoding = list,
+ input_type = stream})
end;
stream(Xml, Options) when is_binary(Xml), is_list(Options) ->
case parse_options(Options, initial_state()) of
@@ -124,17 +129,14 @@ stream(Xml, Options) when is_binary(Xml), is_list(Options) ->
[],
State#xmerl_sax_parser_state.event_state};
{Xml1, State1} ->
- parse(Xml1, State1, ParseFunction)
+ parse_binary(Xml1,
+ State1#xmerl_sax_parser_state{input_type = stream},
+ ParseFunction)
end
end.
-
-%%======================================================================
-%% Internal functions
-%%======================================================================
-
%%----------------------------------------------------------------------
-%% Function: parse(Encoding, Xml, State, F) -> Result
+%% Function: parse_binary(Encoding, Xml, State, F) -> Result
%% Input: Encoding = atom()
%% Xml = [integer()] | binary()
%% State = #xmerl_sax_parser_state
@@ -144,15 +146,15 @@ stream(Xml, Options) when is_binary(Xml), is_list(Options) ->
%% EventState = term()
%% Description: Chooses the correct parser depending on the encoding.
%%----------------------------------------------------------------------
-parse(Xml, #xmerl_sax_parser_state{encoding=utf8}=State, F) ->
+parse_binary(Xml, #xmerl_sax_parser_state{encoding=utf8}=State, F) ->
xmerl_sax_parser_utf8:F(Xml, State);
-parse(Xml, #xmerl_sax_parser_state{encoding={utf16,little}}=State, F) ->
+parse_binary(Xml, #xmerl_sax_parser_state{encoding={utf16,little}}=State, F) ->
xmerl_sax_parser_utf16le:F(Xml, State);
-parse(Xml, #xmerl_sax_parser_state{encoding={utf16,big}}=State, F) ->
+parse_binary(Xml, #xmerl_sax_parser_state{encoding={utf16,big}}=State, F) ->
xmerl_sax_parser_utf16be:F(Xml, State);
-parse(Xml, #xmerl_sax_parser_state{encoding=latin1}=State, F) ->
+parse_binary(Xml, #xmerl_sax_parser_state{encoding=latin1}=State, F) ->
xmerl_sax_parser_latin1:F(Xml, State);
-parse(_, #xmerl_sax_parser_state{encoding=Enc}, _) ->
+parse_binary(_, #xmerl_sax_parser_state{encoding=Enc}, _) ->
{error, lists:flatten(io_lib:format("Charcter set ~p not supported", [Enc]))}.
%%----------------------------------------------------------------------