Skip to content

Commit

Permalink
Disable subtype search on fake types.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicRU committed Sep 30, 2020
1 parent 86f5b1c commit acd59cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/erlsom_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
xmlString/1,
strip/1,
toUnicode/1, detect_encoding/1, detectEncoding/3,
findFile/4, find_xsd/4, findType/6,
findFile/4, find_xsd/4, findType/6, findType/2,
readImportFile/1,
newTree/0, addTreeElement/3, isAncestor/3, getAncestor/2,
getLeaves/2,
Expand Down Expand Up @@ -581,13 +581,15 @@ toUnicode(Bin) ->
autodetect(Bin).

findType(TypeReference, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping) ->
case findXsiType(Attributes) of
{value, XsiType} ->
findDerivedType(TypeReference, XsiType, Types, TypeHierarchy, Namespaces, NamespaceMapping);
_ -> findType(TypeReference, Types)
end.

findType(TypeReference, Types) ->
case lists:keysearch(TypeReference, #type.nm, Types) of
{value, Value} ->
case findXsiType(Attributes) of
{value, XsiType} ->
findDerivedType(TypeReference, XsiType, Types, TypeHierarchy, Namespaces, NamespaceMapping);
_ -> Value
end;
{value, Value} -> Value;
_Else ->
throw({error, "Type not found: " ++ atom_to_list(TypeReference)})
end.
Expand Down
19 changes: 12 additions & 7 deletions src/erlsom_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
-include("exception.hrl").
-include("erlsom_sax.hrl").
-include("erlsom_parse.hrl"). %% the record definitions
-import(erlsom_lib, [findType/6]).
-import(erlsom_lib, [convertPCData/4]).


Expand Down Expand Up @@ -412,7 +411,7 @@ stateMachine(Event,
case lists:keysearch(Name, #alt.tag, Alternatives) of
{value, #alt{tp = TypeReference, rl = RealElement}} ->
%% look for the type description
TheType = findType(TypeReference, Types, AttributeValues, TypeHierarchy, Namespaces, NamespaceMapping),
TheType = findType(RealElement, TypeReference, Types, AttributeValues, TypeHierarchy, Namespaces, NamespaceMapping),
#type{tp = Tp, els = Elements2, mxd = Mixed} = TheType,
%% create new record for this element &
%% process the attributes
Expand Down Expand Up @@ -563,7 +562,7 @@ stateMachine(Event, State = #state{currentState = #altState{name=Name, type=Type
%% not text: a complex type.
%% look for the type discription
%% debug("Not text: a complex type"),
TypeDef = findType(Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
TypeDef = findType(Real, Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
%% #type{els = Elements, atts = ListOfAttributes, nr = NrOfElements} = TypeDef,
%% create new record for this element
%% process the attributes
Expand Down Expand Up @@ -825,7 +824,7 @@ stateMachine(Event, State = #state{currentState = #cs{re = RemainingElements,
%% look for the type discription
%% debug("Not text: a complex type"),
%% Look for xsi:type attribute
TypeDef = findType(Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
TypeDef = findType(RealElement2, Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
#type{els = Elements, tp = Tp, mxd = Mxd} = TypeDef,
case RealElement2 of
true -> NewMxd = Mxd;
Expand Down Expand Up @@ -918,7 +917,7 @@ stateMachine(Event, State = #state{currentState = #cs{re = RemainingElements,
NewState = undefined
end; %}
true -> %% not a real element
TypeDef = findType(Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
TypeDef = erlsom_lib:findType(Type, Types),
%% debug(Type),
#type{els = Elements, tp = Tp, mxd = Mxd} = TypeDef,
NewRecord = newRecord(TypeDef, StoreAnyAttr),
Expand Down Expand Up @@ -992,7 +991,7 @@ stateMachine(Event, State = #state{currentState = #cs{re = RemainingElements,
%% TODO: this seems to be a bit odd? What is this is a reference to a group?
%% a helper element for this text
%% look for the type discription
TypeDef = findType(Type, Types, [], TypeHierarchy, Namespaces, NamespaceMapping),
TypeDef = erlsom_lib:findType(Type, Types),
%% create new record for this element
%% (can't have any attributes)
NewRecord = newRecord(TypeDef, StoreAnyAttr),
Expand Down Expand Up @@ -1090,7 +1089,7 @@ stateMachine(Event, State = #state{currentState = #all{re = RemainingElements,
%% not text: a complex type.
%% look for the type discription
%% Look for xsi:type attribute
TypeDef = findType(Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
TypeDef = findType(RealElement, Type, Types, Attributes, TypeHierarchy, Namespaces, NamespaceMapping),
#type{els = Elements, tp = Tp} = TypeDef,
%% create new record for this element
%% process the attributes
Expand Down Expand Up @@ -1544,3 +1543,9 @@ applyValueFun(skip, ElementRecord, _Acc) ->
applyValueFun(ValueFun, ElementRecord, Acc) ->
{_, Result} = ValueFun(ElementRecord, Acc),
{result, Result}.


findType(false, TypeReference, Types, _AttributeValues, _TypeHierarchy, _Namespaces, _NamespaceMapping) ->
erlsom_lib:findType(TypeReference, Types);
findType(_, TypeReference, Types, AttributeValues, TypeHierarchy, Namespaces, NamespaceMapping) ->
erlsom_lib:findType(TypeReference, Types, AttributeValues, TypeHierarchy, Namespaces, NamespaceMapping).

0 comments on commit acd59cb

Please sign in to comment.