Skip to content

Commit 57de181

Browse files
committed
forgot to save README file..
1 parent a47194e commit 57de181

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

README.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ This document is stored in a file called "minimal.xml", and read into a
7575
variable called Xml by the following commands in the shell:
7676

7777
```
78-
1> {ok, Xml} = file:read\_file("minimal.xml").
78+
1> {ok, Xml} = file:read_file("minimal.xml").
7979
{ok,<<"<foo attr=\"baz\"><bar>x</bar><bar>y</bar></foo>\r\n">>}
8080
```
8181

@@ -126,7 +126,7 @@ The next example does something slightly more meaningful: it counts the number o
126126
{ok,2,"\r\n"}
127127
```
128128

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.
130130
(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.)
131131

132132
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:
416416
‘anyAttributes’, and if these are present in the XML document, then the
417417
values will be found here (as a list of attribute-value pairs). Note
418418
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
420420
will not be there.
421421

422422
It should be noted that there is quite a bit of information in po.xsd that is not used by erlsom:
423423

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+
424442
- Only in a limited number of situations does erlsom do type checking and
425443
translation: only if an element is defined as integer, int, boolean or QName
426444
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.
589607

590608
Klacke (Claes Wickstrom) has provided a makefile. This should enable Unix users to install Erlsom easily.
591609

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.
593611

594612
- Put all the files into the directory `ROOT/lib/erlsom-1.2.1/src`, where ROOT
595613
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
700718
types (float, positiveInteger, gYear etc), and also to types that are
701719
restricted (using 'facets') or extended (for example 'union' types). The only
702720
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+
703727
- Key, Unique etc. are not supported - if these elements occur in the XSD, they
704728
are simply ignored.
705729

@@ -718,7 +742,7 @@ The data binder has the following additional limitation:
718742
<table width="100%" border="1" cellspacing="0" cellpadding="2">
719743
<tr><td valign="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>
720744
<tr><td valign="top">Annotation</td><td>Ignored (anything enclosed in <documentation></documentation> is ignored).</td></tr>
721-
<tr><td valign="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><td valign="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>
722746
<tr><td valign="top">anyAttribute</td><td>Supported</td></tr>
723747
<tr><td valign="top">Appinfo</td><td>Ignored (anything enclosed in <documentation></documentation> is ignored. </td></tr>
724748
<tr><td valign="top">Attribute</td><td>Supported</td></tr>
@@ -732,8 +756,8 @@ The data binder has the following additional limitation:
732756
<tr><td valign="top">Extension</td><td>Supported</td></tr>
733757
<tr><td valign="top">Field</td><td>Ignored (anything enclosed in <code><unique></unique></code> is ignored).</td></tr>
734758
<tr><td valign="top">Group</td><td>Supported.</td></tr>
735-
<tr><td valign="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><td valign="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><td valign="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><td valign="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>
737761
<tr><td valign="top">Key</td><td>Ignored.</td></tr>
738762
<tr><td valign="top">Keyref</td><td>Ignored</td></tr>
739763
<tr><td valign="top">Length</td><td>Ignored (all restrictions on simple types are ignored - those types are treated as ‘string’)</td></tr>
@@ -743,7 +767,7 @@ The data binder has the following additional limitation:
743767
<tr><td valign="top">minInclusive</td><td>(see maxInclusive) </td></tr>
744768
<tr><td valign="top">minLength</td><td>(see maxInclusive) </td></tr>
745769
<tr><td valign="top">Pattern</td><td>(see maxInclusive) </td></tr>
746-
<tr><td valign="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><td valign="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>
747771
<tr><td valign="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>
748772
<tr><td valign="top">Schema</td><td>Supported</td></tr>
749773
<tr><td valign="top">Selector</td><td>Ignored (anything enclosed in <code><unique></unique></code> is ignored).</td></tr>

0 commit comments

Comments
 (0)