You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -126,7 +126,7 @@ The next example does something slightly more meaningful: it counts the number o
126
126
{ok,2,"\r\n"}
127
127
```
128
128
129
-
To describe it in a rather formal way: `parse\_sax(Xml, Acc0, Fun)` calls Fun(Event, AccIn) on successive ‘XML events’ that result from parsing Xml, starting with AccIn == Acc0. Fun/2 must return a new accumulator which is passed to the next call. The function returns {ok, AccOut, Tail}, where AccOut is the final value of the accumulator and Tail the list of characters that follow after the last tag of the XML document. In this example AccOut == 2, since the tag occurs twice.
129
+
To describe it in a rather formal way: `parse_sax(Xml, Acc0, Fun)` calls Fun(Event, AccIn) on successive ‘XML events’ that result from parsing Xml, starting with AccIn == Acc0. Fun/2 must return a new accumulator which is passed to the next call. The function returns {ok, AccOut, Tail}, where AccOut is the final value of the accumulator and Tail the list of characters that follow after the last tag of the XML document. In this example AccOut == 2, since the tag occurs twice.
130
130
(Notice how similar this is to lists:foldl(Fun, Acc0, Sax\_events), assuming that Sax\_events is the list of Sax events - I more or less copied this description from the documentation of the lists module.)
131
131
132
132
It may still not be very clear to you how this SAX parser can be used to produce useful results. There are some additional examples in the examples directory of the Erlsom distribution. If you are still not convinced you can try to decipher the source code for the ‘data binder’ mode (erlsom_parse.erl) - this was also built on top of the SAX parser.
@@ -416,11 +416,29 @@ As can be seen from the example:
416
416
‘anyAttributes’, and if these are present in the XML document, then the
417
417
values will be found here (as a list of attribute-value pairs). Note
418
418
that this can be avoided by passing the option {include_any_attribs,
419
-
false} erlsom:compile_xsd_file: in that case the ‘anyAttribs’ element
419
+
false} to erlsom:compile_xsd_file: in that case the ‘anyAttribs’ element
420
420
will not be there.
421
421
422
422
It should be noted that there is quite a bit of information in po.xsd that is not used by erlsom:
423
423
424
+
- Only in a limited number of situations does erlsom do type checking and
425
+
translation: only if an element is defined as integer, int, boolean or QName
426
+
without any further restrictions or extensions. The ‘quantity’ element doesn’t
427
+
meet these conditions, since (a) it is a positiveInteger, and (b) it is
428
+
restricted. A value for the quantity element of Ten or -1 would not result in
429
+
an error or warning, and the string value is not translated to an Erlang
430
+
integer. This also applies for the user defined simpleTypes, like SKU in the
431
+
example.
432
+
433
+
Note that this behaviour can be modified by passing the option `{strict,
434
+
true}` to erlsom:compile_xsd_file: in that case more types will be
435
+
checked and mapped to Erlang types, for example `float` and `long`. This
436
+
also applies to `positiveInteger`, but since the limitation that this
437
+
only works for types without restrictions or extensions still holds, it would not
438
+
make any difference for the value of ‘quantity’.
439
+
440
+
It should be noted that there is quite a bit of information in po.xsd that is not used by erlsom:
441
+
424
442
- Only in a limited number of situations does erlsom do type checking and
425
443
translation: only if an element is defined as integer, int, boolean or QName
426
444
without any further restrictions or extensions. The ‘quantity’ element doesn’t
@@ -589,7 +607,7 @@ The easiest way to install Erlsom is probably to use rebar.
589
607
590
608
Klacke (Claes Wickstrom) has provided a makefile. This should enable Unix users to install Erlsom easily.
591
609
592
-
Anyway, even for Windows users and without rebar, installing erlsom should be straightforward. One way to do it would is described below.
610
+
Anyway, even for Windows users and without rebar, installing erlsom should be straightforward. One way to do it is described below.
593
611
594
612
- Put all the files into the directory `ROOT/lib/erlsom-1.2.1/src`, where ROOT
595
613
is the directory that contains Erlang (C:\Program Files\erl5.6.1 on my Windows system).
@@ -700,6 +718,12 @@ Some checks/validity constraints are accepted in the XSD, but not enforced durin
700
718
types (float, positiveInteger, gYear etc), and also to types that are
701
719
restricted (using 'facets') or extended (for example 'union' types). The only
702
720
exceptions are Integer, Boolean and QName, these are translated.
721
+
722
+
If the option `{strict, true}` is used when compiling the XSD, a number
723
+
of additional types will be translated (and checked): Float, Double and
724
+
all types that are derived from the Integer type, such as
725
+
positiveInteger, nonNegativeInteger, Long, unsignedLong etc.
726
+
703
727
- Key, Unique etc. are not supported - if these elements occur in the XSD, they
704
728
are simply ignored.
705
729
@@ -718,7 +742,7 @@ The data binder has the following additional limitation:
<tr><tdvalign="top">All</td><td>Supported. The parser puts the elements into the resulting record in a fixed place (independent of the order in which they are received).</td></tr>
720
744
<tr><tdvalign="top">Annotation</td><td>Ignored (anything enclosed in <documentation></documentation> is ignored).</td></tr>
721
-
<tr><tdvalign="top">Any</td><td>Supported. However, only elements that are included in the model will show up in the result. Elements are part of the model if they are included in the XSD that was compiled, or if they have been added using erlsom:add\_file().</td></tr>
745
+
<tr><tdvalign="top">Any</td><td>Supported. However, only elements that are included in the model will show up in the result. Elements are part of the model if they are included in the XSD that was compiled, or if they have been added using erlsom:add_file().</td></tr>
<tr><tdvalign="top">Import</td><td>Supported. However, the support for finding the imported files is limited. See (and modify, if necessary...) the function findFile in erlsom\_lib.erl. </td></tr>
736
-
<tr><tdvalign="top">Include</td><td>Supported. However, the support for finding the included files is limited. See (and modify, if necessary...) the function findFile in erlsom\_lib.erl.</td></tr>
759
+
<tr><tdvalign="top">Import</td><td>Supported. However, the support for finding the imported files is limited. See (and modify, if necessary...) the function findFile in erlsom_lib.erl. </td></tr>
760
+
<tr><tdvalign="top">Include</td><td>Supported. However, the support for finding the included files is limited. See (and modify, if necessary...) the function findFile in erlsom_lib.erl.</td></tr>
<tr><tdvalign="top">Redefine</td><td>Supported. However, the support for finding the imported files is limited. See (and modify, if necessary...) the function findFile in erlsom\_lib.erl.</td></tr>
770
+
<tr><tdvalign="top">Redefine</td><td>Supported. However, the support for finding the imported files is limited. See (and modify, if necessary...) the function findFile in erlsom_lib.erl.</td></tr>
747
771
<tr><tdvalign="top">Restriction</td><td>Supported as a way to create a derived complex type (but it is not checked whether this is really a restriction of the base type). Ignored on simpleTypes (all restrictions on simple types are ignored - those types are treated as ‘string’)</td></tr>
0 commit comments