diff options
Diffstat (limited to 'lib/xmerl/src/xmerl_xsd.erl')
-rw-r--r-- | lib/xmerl/src/xmerl_xsd.erl | 162 |
1 files changed, 80 insertions, 82 deletions
diff --git a/lib/xmerl/src/xmerl_xsd.erl b/lib/xmerl/src/xmerl_xsd.erl index 3038a54ee6..a89b3159ec 100644 --- a/lib/xmerl/src/xmerl_xsd.erl +++ b/lib/xmerl/src/xmerl_xsd.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2006-2013. All Rights Reserved. +%% Copyright Ericsson AB 2006-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ %% <dd>It is possible by this option to provide a state with process %% information from an earlier validation.</dd> %% </dl> +%% @type filename() = string() %% @end %%%------------------------------------------------------------------- -module(xmerl_xsd). @@ -64,12 +65,10 @@ %%---------------------------------------------------------------------- %% External exports %%---------------------------------------------------------------------- --export([ - validate/2,validate/3,process_validate/2,process_validate/3, +-export([validate/2,validate/3,process_validate/2,process_validate/3, process_schema/1,process_schema/2, process_schemas/1,process_schemas/2, - state2file/1,state2file/2,file2state/1,format_error/1 - ]). + state2file/1,state2file/2,file2state/1,format_error/1]). %%---------------------------------------------------------------------- %% Internal exports @@ -140,7 +139,7 @@ state2file(S=#xsd_state{schema_name=SN}) -> %% @spec state2file(State,FileName) -> ok | {error,Reason} %% State = global_state() -%% FileName = filename() +%% FileName = string() %% @doc Saves the schema state with all information of the processed %% schema in a file. You can provide the file name for the saved %% state. FileName is saved with the <code>.xss</code> extension @@ -155,7 +154,7 @@ state2file(S,FileName) when is_record(S,xsd_state) -> %% @spec file2state(FileName) -> {ok,State} | {error,Reason} %% State = global_state() -%% FileName = filename() +%% FileName = string() %% @doc Reads the schema state with all information of the processed %% schema from a file created with <code>state2file/[1,2]</code>. The %% format of this file is internal. The state can then be used @@ -204,7 +203,7 @@ xmerl_xsd_vsn_check(S=#xsd_state{vsn=MD5_VSN}) -> process_validate(Schema,Xml) -> process_validate(Schema,Xml,[]). %% @spec process_validate(Schema,Element,Options) -> Result -%% Schema = filename() +%% Schema = string() %% Element = XmlElement %% Options = option_list() %% Result = {ValidXmlElement,State} | {error,Reason} @@ -284,7 +283,7 @@ validate3(_,_,S) -> process_schema(Schema) -> process_schema(Schema,[]). %% @spec process_schema(Schema,Options) -> Result -%% Schema = filename() +%% Schema = string() %% Result = {ok,State} | {error,Reason} %% State = global_state() %% Reason = [ErrorReason] | ErrorReason @@ -326,7 +325,7 @@ process_schema2({SE,_},State,_Schema) -> process_schemas(Schemas) -> process_schemas(Schemas,[]). %% @spec process_schemas(Schemas,Options) -> Result -%% Schemas = [{NameSpace,filename()}|Schemas] | [] +%% Schemas = [{NameSpace,string()}|Schemas] | [] %% Result = {ok,State} | {error,Reason} %% Reason = [ErrorReason] | ErrorReason %% Options = option_list() @@ -550,7 +549,7 @@ element_content({attribute,S=#xsd_state{scope=Scope}},Att,Env) -> {AttRef,add_ref(S,AttRef)}; Name -> {AttrType,S2} = attribute_type(Att,[Name|Env],S), - S3 = check_cm(attribute,allowed_content(attribute,Env),AttrType,S2), + S3 = check_cm(attribute,allowed_content(attribute,Env),AttrType,S2), {Attr,S4} = attribute_properties(Att#xmlElement.attributes, #schema_attribute{type=AttrType},S3), Object = {attribute, @@ -568,7 +567,7 @@ element_content({element,S},El,Env) -> %% 3.3.3 bullet 2.2 S3 = element_forbidden_properties(El,S2), S4 = element_forbidden_content(El#xmlElement.content,S3), - ElRef = + ElRef = {element, {get_QName(Ref,El#xmlElement.namespace,reset_scope(S)), Occ}}, @@ -813,7 +812,6 @@ element_content({restriction,S},R,Env) -> %% base (resolved by base_type/1) or the type defined in content. {CM,S2} = type(R#xmlElement.content,S,[restriction|Env]), S3 = check_cm(restriction,allowed_content(restriction,Env),CM,S2), - {BaseTypeName,CM2,S4} = restriction_base_type(R,CM,S3), %% a QName %% S5 = add_circularity_mark(BaseTypeName,S4), BaseTypeType = base_type_type(Env), @@ -1178,7 +1176,7 @@ rename_redef_group(Name={LN,Scope,NS},S) -> NewName = {LN,['#redefine'|Scope],NS}, case resolve({group,NewName},S) of {SG=#schema_group{name=Name},_} -> - save_object({group,SG#schema_group{name=NewName}},S), + _ = save_object({group,SG#schema_group{name=NewName}},S), NewName; _ -> failed @@ -1735,20 +1733,20 @@ allowed_content(SorC,_Parents) when SorC==sequence;SorC==choice -> {choice,{1,1}},{sequence,{1,1}}, {any,{1,1}}], occurance={0,unbounded}}]}; -allowed_content(E,_Parents) - when E==any;E==selector;E==field;E==notation;E==include;E==import; - E==anyAttribute -> - {annotation,{0,1}}; -allowed_content(UKK,_Parents) when UKK==unique;UKK==key;UKK==keyref-> - #chain{content= - [{annotation,{0,1}}, - #chain{content= - [{selector,{1,1}},{selector,{1,unbounded}}]}]}; -allowed_content(annotation,_Parents) -> - #alternative{content=[{appinfo,{1,1}},{documentation,{1,1}}], - occurance={0,unbounded}}; -allowed_content(E,_Parents) when E==appinfo;E==documentation -> - {any,{0,unbounded}}; +%% allowed_content(E,_Parents) +%% when E==any;E==selector;E==field;E==notation;E==include;E==import; +%% E==anyAttribute -> +%% {annotation,{0,1}}; +%% allowed_content(UKK,_Parents) when UKK==unique;UKK==key;UKK==keyref-> +%% #chain{content= +%% [{annotation,{0,1}}, +%% #chain{content= +%% [{selector,{1,1}},{selector,{1,unbounded}}]}]}; +%% allowed_content(annotation,_Parents) -> +%% #alternative{content=[{appinfo,{1,1}},{documentation,{1,1}}], +%% occurance={0,unbounded}}; +%% allowed_content(E,_Parents) when E==appinfo;E==documentation -> +%% {any,{0,unbounded}}; allowed_content(simpleType,_Parents) -> #chain{content= [{annotation,{0,1}}, @@ -1768,22 +1766,22 @@ allowed_content(restriction,Parents) -> end; allowed_content(LU,_Parent) when LU==list;LU==union -> #chain{content=[{annotation,{0,1}},{simpleType,{0,1}}]}; -allowed_content(schema,_) -> - #chain{content= - [#alternative{content= - [{include,{1,1}},{import,{1,1}}, - {redefine,{1,1}},{annotation,{1,1}}], - occurance={0,1}}, - #chain{content= - [#alternative{content= - [#alternative{content= - [{simpleType,{1,1}},{complexType,{1,1}}, - {group,{1,1}},{attributeGroup,{1,1}}]}, - {element,{1,1}}, - {attribute,{1,1}}, - {notation,{1,1}}]}, - {annotation,{0,unbounded}}], - occurance={0,unbounded}}]}; +%% allowed_content(schema,_) -> +%% #chain{content= +%% [#alternative{content= +%% [{include,{1,1}},{import,{1,1}}, +%% {redefine,{1,1}},{annotation,{1,1}}], +%% occurance={0,1}}, +%% #chain{content= +%% [#alternative{content= +%% [#alternative{content= +%% [{simpleType,{1,1}},{complexType,{1,1}}, +%% {group,{1,1}},{attributeGroup,{1,1}}]}, +%% {element,{1,1}}, +%% {attribute,{1,1}}, +%% {notation,{1,1}}]}, +%% {annotation,{0,unbounded}}], +%% occurance={0,unbounded}}]}; allowed_content(redefine,_Parents) -> #alternative{content= [{annotation,{1,1}}, @@ -1803,31 +1801,31 @@ allowed_content(extension,Parents) -> allowed_content2(extension,simpleContent); _ -> allowed_content2(extension,complexContent) - end; -allowed_content(minExclusive,_Parents) -> - []; -allowed_content(minInclusive,_Parents) -> - []; -allowed_content(maxExclusive,_Parents) -> - []; -allowed_content(maxInclusive,_Parents) -> - []; -allowed_content(totalDigits,_Parents) -> - []; -allowed_content(fractionDigits,_Parents) -> - []; -allowed_content(length,_Parents) -> - []; -allowed_content(minLength,_Parents) -> - []; -allowed_content(maxLength,_Parents) -> - []; -allowed_content(enumeration,_Parents) -> - []; -allowed_content(whiteSpace,_Parents) -> - []; -allowed_content(pattern,_Parents) -> - []. + end. +%% allowed_content(minExclusive,_Parents) -> +%% []; +%% allowed_content(minInclusive,_Parents) -> +%% []; +%% allowed_content(maxExclusive,_Parents) -> +%% []; +%% allowed_content(maxInclusive,_Parents) -> +%% []; +%% allowed_content(totalDigits,_Parents) -> +%% []; +%% allowed_content(fractionDigits,_Parents) -> +%% []; +%% allowed_content(length,_Parents) -> +%% []; +%% allowed_content(minLength,_Parents) -> +%% []; +%% allowed_content(maxLength,_Parents) -> +%% []; +%% allowed_content(enumeration,_Parents) -> +%% []; +%% allowed_content(whiteSpace,_Parents) -> +%% []; +%% allowed_content(pattern,_Parents) -> +%% []. @@ -1905,9 +1903,9 @@ set_occurance(Ch = #chain{},Occ) -> set_occurance(Alt = #alternative{},Occ) -> Alt#alternative{occurance=Occ}; set_occurance({Name,_},Occ) when is_atom(Name) -> - {Name,Occ}; -set_occurance(CM,_) -> - CM. + {Name,Occ}. +%% set_occurance(CM,_) -> +%% CM. process_external_schema_once(E,Namespace,S) when is_record(E,xmlElement) -> @@ -3436,7 +3434,7 @@ check_keys([Key=#id_constraint{selector={selector,SelectorPath}, {L,S1} when length(L)==length(TargetNodeSet) -> %% Part1: 3.11.4.4.2.1 S2 = key_sequence_uniqueness(L,XMLEl,S1), - save_key(Key#id_constraint{key_sequence=L},S2), + _ = save_key(Key#id_constraint{key_sequence=L},S2), S2; {Err,S1} -> acc_errs(S1,{error_path(XMLEl,XMLEl#xmlElement.name),?MODULE, @@ -4014,7 +4012,7 @@ merge_derived_types(XSDType,InstType,Blocks,Mode,S) -> {error,S2} -> {InstType,S2}; {MergedType,S2} -> - save_merged_type(MergedType,S2), + _ = save_merged_type(MergedType,S2), {MergedType,S2} end. @@ -4970,7 +4968,7 @@ save_schema_element(CM,S=#xsd_state{elementFormDefault = EFD, undefined -> []; _ -> TN end, - save_in_table({schema,TN2},Schema2,S), + _ = save_in_table({schema,TN2},Schema2,S), save_to_file(S). %% other_global_elements(S,ElementList) -> @@ -5006,13 +5004,13 @@ save_to_file(S=#xsd_state{tab2file=TF}) -> {ok,IO}=file:open(filename:rootname(S#xsd_state.schema_name)++".tab", [write]), io:format(IO,"~p~n",[catch ets:tab2list(S#xsd_state.table)]), - file:close(IO); + ok = file:close(IO); false -> ok; IOFile -> {ok,IO}=file:open(IOFile,[write]), io:format(IO,"~p~n",[catch ets:tab2list(S#xsd_state.table)]), - file:close(IO) + ok = file:close(IO) end. save_merged_type(Type=#schema_simple_type{},S) -> @@ -5034,25 +5032,25 @@ save_idc(unique,IDConstr,S) -> save_unique(IDConstr,S). save_key(Key,S) -> - save_object({key,Key},S), + _ = save_object({key,Key},S), S. save_keyref(KeyRef=#id_constraint{category=keyref},S) -> S1 = add_keyref(KeyRef,S), - save_object({keyref,KeyRef},S1), + _ = save_object({keyref,KeyRef},S1), S1; save_keyref(_,S) -> S. save_unique(Unique,S) -> - save_object({unique,Unique},S), + _ = save_object({unique,Unique},S), S. save_substitutionGroup([],S) -> S; save_substitutionGroup([{Head,Members}|SGs],S) -> %% save {head,[members]} - save_in_table({substitutionGroup,Head},Members,S), + _ = save_in_table({substitutionGroup,Head},Members,S), %% save {member,head}, an element can only be a member in one %% substitutionGroup lists:foreach(fun(X)->save_in_table({substitutionGroup_member,X},Head,S) end,Members), @@ -5429,7 +5427,7 @@ add_key_once(Key,N,El,L) -> %% {filename:join([[io_lib:format("/~w(~w)",[X,Y])||{X,Y}<-Parents],Type]),Pos}. %% @spec format_error(Errors) -> Result -%% Errors = error_tuple() | [error_tuple()] +%% Errors = tuple() | [tuple()] %% Result = string() | [string()] %% @doc Formats error descriptions to human readable strings. format_error(L) when is_list(L) -> |