Skip to content
Browse files

Various errors solved

- corrected erlsom_add to deal with type hierarchies
- fixed problem with type hierarchy
- fixed problem with import in include
- accept id attribute in schema element
- remove obsolete guards
- fixed problem with attribute groups
- fixed problem with whitespace in text elements
  • Loading branch information...
1 parent c77ab13 commit c87a9ee72d01cb28b60b00b9449aaa5416fbbca7 @willemdj committed
View
2 src/erlsom.erl
@@ -209,7 +209,7 @@ scan(Xml, Model, Options) ->
scan2(Xml, State, Options) ->
case catch erlsom_sax:parseDocument(Xml, State,
- {erlsom_parse, xml2StructCallback},
+ fun erlsom_parse:xml2StructCallback/2,
Options) of
{error, Message} -> {error, Message};
{'EXIT', Message} -> throw({'EXIT', Message});
View
6 src/erlsom_add.erl
@@ -56,7 +56,8 @@ add(Xsd, Options, Model1) ->
add_xsd_model(Model1) ->
add_model(Model1, erlsom_parseXsd:xsdModel()).
-add_model(Model1 = #model{tps = Tps, nss = Nss, tns = Tns}, _Model2 = #model{tps = NewTps, nss = NewNss}) ->
+add_model(Model1 = #model{tps = Tps, nss = Nss, tns = Tns, th = Th},
+ _Model2 = #model{tps = NewTps, nss = NewNss, th = NewTh}) ->
[Document | OtherTypes] = Tps,
#type{nm = '_document', els = [Element]} = Document,
#el{alts = Alts} = Element,
@@ -70,10 +71,11 @@ add_model(Model1 = #model{tps = Tps, nss = Nss, tns = Tns}, _Model2 = #model{tps
CombinedDocument = Document#type{els = [CombinedElement]},
CombinedTypes = [CombinedDocument | lists:umerge(lists:usort(OtherTypes), lists:usort(OtherNewTypes))],
CombinedNss = lists:umerge(lists:usort(Nss), lists:usort(NewNss)),
+ CombinedTh = lists:umerge(lists:usort(Th), lists:usort(NewTh)),
Info = #schemaInfo{namespaces = CombinedNss, targetNamespace = Tns},
UpdatedTypes = erlsom_pass2:pass5(CombinedTypes, Info),
- Model1#model{tps = UpdatedTypes, nss = CombinedNss}.
+ Model1#model{tps = UpdatedTypes, nss = CombinedNss, th = CombinedTh}.
View
12 src/erlsom_compile.erl
@@ -18,6 +18,11 @@
%%%
%%% Author contact: w.a.de.jong@gmail.com
+
+%%% Version history:
+%%% 22-04-2009: fixed bug in processing of import inside include - see
+%%% comment marked 20090422.
+
%%% ===================================================================
%%% Translates the XSD into the model used by erlsom_parse.
%%% ===================================================================
@@ -287,6 +292,8 @@ processImports([Impt = #includeType{} | Tail], Acc = #p1acc{includeDirs = Dirs,
nsp = Prefix,
seqCnt = Acc3#p1acc.seqCnt,
attGrps = Acc3#p1acc.attGrps,
+ nss = Acc3#p1acc.nss, %% 20090422: added this line to make
+ %% namespaces known.
atts = Acc3#p1acc.atts},
processImports(Tail, Acc4);
processImports([#redefineType{schemaLocation = Location,
@@ -441,7 +448,10 @@ transformTypes([#globalComplexTypeType{name=Name, model=Model, attributes=Attrib
transformTypes(Tail, Acc2#p1acc{path = [], tps = [Type2 | ResultSoFar]});
%%-record(globalSimpleTypeType, {name, annotation, model}).
-transformTypes([#globalSimpleTypeType{name=Name, model=undefined}| Tail],
+%% TODO: better would be to avoid getting the 'any' stuff in the
+%% translation of the XSD alltogether.
+%% transformTypes([#globalSimpleTypeType{name=Name, model=undefined}| Tail],
+transformTypes([#globalSimpleTypeType{name=Name}| Tail],
Acc = #p1acc{tps = ResultSoFar, nsp = Prefix}) ->
Type = #typeInfo{typeName = erlsom_lib:makeTypeName(Name, Prefix), typeRef = "##string", global = false,
typeType = simpleType},
View
2 src/erlsom_compile.hrl
@@ -26,7 +26,7 @@
%% records for the structures as found in the XSD
-record(schemaType,
{elInfo, targetNamespace, elementFormDefault, attributeFormDefault, blockDefault, finalDefault,
- version, imports, elements}).
+ version, id, imports, elements}).
-record(importType, {elInfo, id, namespace, schemaLocation, annotation}).
-record(includeType, {elInfo, id, schemaLocation, annotation}).
-record(redefineType, {elInfo, id, schemaLocation, elements}).
View
3 src/erlsom_lib.erl
@@ -125,6 +125,7 @@ addTreeElement(Child, Parent, Tree) ->
[{Child, Parent} | Tree].
%% find out whether Ancestor is really an Ancestor of Element.
+isAncestor(Element, Element, _Tree) -> true; %% added because of problem reported by Stu
isAncestor(Ancestor, Element, Tree) ->
case lists:keysearch(Element, 1, Tree) of
{value, {_, Ancestor}} -> true;
@@ -594,7 +595,7 @@ detect_encoding3(Variables) ->
utf8
end.
-encoding_type(Cs) when list(Cs) ->
+encoding_type(Cs) when is_list(Cs) ->
case to_lower(Cs) of
"iso-8859-1" -> 'iso-8859-1';
"iso_8859_1" -> 'iso-8859-1';
View
12 src/erlsom_parse.erl
@@ -294,7 +294,17 @@ xml2StructCallback(Event, State) ->
stateMachine(Event, State);
{characters, _Characters} ->
stateMachine(Event, State);
- {ignorableWhitespace, _Characters} -> State;
+ {ignorableWhitespace, Characters} ->
+ case State of
+ #state{currentState = #anyState{}} ->
+ stateMachine({characters, Characters}, State);
+ #state{currentState = {'#PCDATA', _, _}} ->
+ stateMachine({characters, Characters}, State);
+ #state{currentState = {'#text', _, _}} ->
+ stateMachine({characters, Characters}, State);
+ _ ->
+ State
+ end;
{processingInstruction, _Target, _Data} -> State;
{startPrefixMapping, Prefix, URI} ->
Namespaces = State#state.namespaces,
View
16 src/erlsom_parseXsd.erl
@@ -60,7 +60,7 @@ xsdModel(Namespaces) ->
#alt{tag = 'xsd:annotation', tp = 'annotationType'}],
mn = 0,
mx = unbound,
- nr = 7},
+ nr = 8},
#el{alts = [#alt{tag = 'xsd:element', tp = 'globalElementType'},
#alt{tag = 'xsd:complexType', tp = 'globalComplexTypeType'},
#alt{tag = 'xsd:simpleType', tp = 'globalSimpleTypeType'},
@@ -70,14 +70,15 @@ xsdModel(Namespaces) ->
#alt{tag = 'xsd:annotation', tp = 'annotationType'}],
mn = 0,
mx = unbound,
- nr = 8}],
+ nr = 9}],
atts = [#att{nm = targetNamespace, nr = 1, opt = true, tp = char},
#att{nm = elementFormDefault, nr = 2, opt = true, tp = char},
#att{nm = attributeFormDefault, nr = 3, opt = true, tp = char},
#att{nm = blockDefault, nr = 4, opt = true, tp = char},
#att{nm = finalDefault, nr = 5, opt = true, tp = char},
- #att{nm = version, nr = 6, opt = true, tp = char}],
- nr = 9},
+ #att{nm = version, nr = 6, opt = true, tp = char},
+ #att{nm = id, nr = 7, opt = true, tp = char}],
+ nr = 10},
%% -record(importType, {id, namespace, schemaLocation}).
%% global attribute not supported
@@ -589,7 +590,8 @@ xsdModel(Namespaces) ->
atts = [#att{nm = ref, nr = 1, opt = true, tp = qname},
#att{nm = id, nr = 2, opt = true, tp = char}],
nr = 3}],
- nss = [#ns{prefix = "xsd", uri = "http://www.w3.org/2001/XMLSchema"} | Namespaces]}.
+ nss = [#ns{prefix = "xsd", uri = "http://www.w3.org/2001/XMLSchema"} | Namespaces],
+ th = []}.
xsdModel() ->
xsdModel([]).
@@ -597,6 +599,6 @@ xsdModel() ->
parseXsd(Xsd, Namespaces) ->
%% -record(anyAttr, {prCont, ns}). %% for anyAttributes
GrammarModel = xsdModel(Namespaces),
- {ok, ParsedXsd, _Tail} = erlsom_sax:parseDocument(Xsd, GrammarModel,
- {erlsom_parse, xml2StructCallback}),
+ {ok, ParsedXsd, _Tail} =
+ erlsom_sax:parseDocument(Xsd, GrammarModel, fun erlsom_parse:xml2StructCallback/2),
ParsedXsd.
View
6 src/erlsom_pass2.erl
@@ -314,9 +314,11 @@ translateAttributes([Attribute | Tail], {Acc, AnyAttr}, SeqNr, Info, Count) ->
%% 'Attribute' can also be a reference to an attribute group - which may include 'anyAttribute'
{TranslatedAttributes, AnyAttr2} = translateAttribute(Attribute, SeqNr, Info, Count),
AnyAttr3 = if AnyAttr2 == undefined -> AnyAttr; true -> AnyAttr2 end,
- translateAttributes(Tail, {TranslatedAttributes ++ Acc, AnyAttr3}, SeqNr + length(TranslatedAttributes), Info, Count);
+ %% 20100131: changed the order of the ++ term, to solve issue with attribute groups. See also below
+ translateAttributes(Tail, {Acc ++ TranslatedAttributes, AnyAttr3}, SeqNr + length(TranslatedAttributes), Info, Count);
translateAttributes([], {Acc, AnyAttr}, _SeqNr, _Info, _Count) ->
- {lists:reverse(Acc), AnyAttr}.
+ %% 20100131: removed the list:reverse, because the ++ above already puts them in the right order
+ {Acc, AnyAttr}.
translateElements(undefined, _Acc, _SeqNr, _Types) ->
[];
View
6 src/erlsom_ucs.erl
@@ -48,7 +48,7 @@ decode_utf8(Utf8) ->
%% parameter has value []).
%% The goal is to allow parsing of data in arbitrary blocks.
-from_utf8(Bin) when binary(Bin) ->
+from_utf8(Bin) when is_binary(Bin) ->
from_utf8(binary_to_list(Bin));
from_utf8(List) ->
@@ -229,7 +229,7 @@ from_utf16le(_Bin,_Acc) ->
%%% UTF-8 encoding and decoding
%% TODO: isn't this very inefficient? Building all these lists?
-to_utf8(List) when list(List) -> lists:flatmap(fun to_utf8/1, List);
+to_utf8(List) when is_list(List) -> lists:flatmap(fun to_utf8/1, List);
to_utf8(Ch) -> char_to_utf8_list(Ch).
%% TODO: this is probably not the best way to do this.
@@ -249,7 +249,7 @@ char_to_utf8(Char) ->
%%% - Non-canonical encoding used.
%%% - Surrogate-pair code encoded as UTF-8.
%%% - 16#FFFE or 16#FFFF character in string.
-char_to_utf8_list(Ch) when integer(Ch), Ch >= 0 ->
+char_to_utf8_list(Ch) when is_integer(Ch), Ch >= 0 ->
if Ch < 128 ->
%% 0yyyyyyy
[Ch];
View
7 src/erlsom_writeHrl.erl
@@ -29,9 +29,6 @@
-export([writeHrl/1]).
-export([writeHrlFile/3]).
-export([writeXsdHrlFile/2]).
-%% internal exports
--export([writeType/2]).
--export([writeAttribute/2]).
-include("erlsom_parse.hrl").
-include("erlsom.hrl").
@@ -74,7 +71,7 @@ header() ->
"%% only be used when *writing* an xml document.\n\n".
writeTypes(Types, Acc) ->
- Acc ++ lists:foldl({erlsom_writeHrl, writeType}, [], Types).
+ Acc ++ lists:foldl(fun writeType/2, [], Types).
writeType(#type{nm = '_document'}, Acc) ->
Acc;
@@ -126,7 +123,7 @@ writeAlternatives([#alt{} | _Tail], CountChoices) ->
writeAttributes(Attributes) ->
- lists:foldl({erlsom_writeHrl, writeAttribute}, [], Attributes).
+ lists:foldl(fun writeAttribute/2, [], Attributes).
writeAttribute(#att{nm = Name}, []) -> "'" ++ atom_to_list(Name) ++ "'";
writeAttribute(#att{nm = Name}, Acc) -> Acc ++ ", '" ++ atom_to_list(Name) ++ "'".

0 comments on commit c87a9ee

Please sign in to comment.
Something went wrong with that request. Please try again.