[erlang-questions] \bclarify: Exception on erlsom:write_xsd_hrl_file for XMLSchema

Willem de Jong w.a.de.jong@REDACTED
Wed May 20 22:52:56 CEST 2009


Hello Mike,

You are right, erlsom fails on the xml schema for xml schema. I have to
admit that I wasn't aware of this.

I had a first look:
- the schema for schema uses the "notation" element. Erlsom doesn't support
that -  I don't really know what it is supposed to mean or what to do with
it. I also haven't seen any other XSD that uses it, so far.

- removing the "notation" elements doesn't solve the problem, so there is
another problem somewhere - I'll try to find out whether or not this is
related to the fact that the schema is sort of defining itself - this is a
rather unique case.
If you just wanted to test the capabilities of Erlsom, then I suggest you do
a couple more tests with more "normal" schema's (let me know if you
encounter more problems..). While developing the tool I used the schema for
voiceXML as a kind of benchmark, maybe it is an idea to look at that. It is
quite big and complex - it is amazing how over-engineered some of these
schemas are.

If you really want to use the schema-schema, for example to parse XSDs and
somehow transform them, or to extract information from them or something
like that, then you can try using the "model" for XML schema that Erlsom
itself uses. The function erlsom_parseXsd:xsdModel() returns this model.

For example, you could do:
15> erlsom:scan_file("BookStore.xsd", erlsom_parseXsd:xsdModel()).

the result will look something like this:

{ok,{schemaType,[],"http://www.books.org","qualified<http://www.books.org%22,%22qualified/>
",
        undefined,undefined,undefined,undefined,undefined,
        [{globalElementType,[],"BookStore",undefined,undefined,
             undefined,undefined,undefined,undefined,undefined,undefined,
             undefined,
             {localComplexTypeType,[],undefined,...},
             undefined},
         {globalElementType,[],"Book",undefined,undefined,undefined,
             undefined,undefined,undefined,undefined,undefined,undefined,
             {localComplexTypeType,[],...},
             undefined},
         {globalElementType,[],"Title",
             {qname,"http://www.w3.org/2001/XMLSchema","string",[],"xsd<http://www.w3.org/2001/XMLSchema%22,%22string%22,%5B%5D,%22xsd>
"},
             undefined,undefined,undefined,...

The definitions of the records (schemaType, globalElementType etc.) are in
erlsom_compile.hrl, so if you do rr("erlsom_compile.hrl") first, the results
will look like this:
{ok,#schemaType{
        elInfo = [],targetNamespace = "http://www.books.org",
        elementFormDefault = "qualified",
        attributeFormDefault = undefined,blockDefault = undefined,
        finalDefault = undefined,version = undefined,
        imports = undefined,
        elements =
            [#globalElementType{
                 elInfo = [],name = "BookStore",type = undefined,
                 default = undefined,fixed = undefined,id = undefined,
                 abstract = undefined,substitutionGroup = undefined,
                 final = undefined,nillable = undefined,
                 annotation = undefined,
                 simpl...

Regards,
Willem

On Wed, May 20, 2009 at 1:51 PM, Mike Ziebeck <mike@REDACTED> wrote:

> I thought the schema w3.org/2001/XMLSchema.xsd
> is rather significant regarding XML. So I was
> a bit surprised seeing erlsom:write_xsd_hrl_file
> throwing an Exception. See the attached file for
> reproduction code.
>
> Is there any work in progress fixing this issue?
>
> Error Message:
> ** exception throw: {error,
>                       [{exception,
>                            {error,
>                                {"2 - Unexpected event, expected
> end-tag"}}},
>                        {stack,[schemaType]},
>                        {received,
>                            {startElement,
>                                "http://www.w3.org/2001/XMLSchema",
>                                "notation","xs",
>                                [{attribute,"system",[],[],
>                                     "
> http://www.w3.org/2000/08/XMLSchema.xsd"},
>                                 {attribute,"public",[],[],"structures"},
>                                 {attribute,"name",[],[],
>                                     "XMLSchemaStructures"}]}}]}
>    in function  erlsom_writeHrl:writeXsdHrlFile/2
>    in call from erlsom:write_xsd_hrl_file/3
>
> --
> System: Erlang R13B (erts-5.7.1) [smp:2:2] [rq:2] [async-threads:0]
> [WinXP64]
>
>
>
>
>
>
>
> %% Author: Mike Ziebeck
> %% Created: 20.05.2009
> %% Description: Test case modul for erlsom
> -module(erlsomtest).
>
> %%
> %% Include files
> %%
>
> %%
> %% Exported Functions
> %%
> -export([test/0]).
>
> %%
> %% API Functions
> %%
>
> %%
> %% function:    test/0
> %% description: download + write *.hdr file for www.w3.org/2001/XMLSchema
> %%
> test() ->
>    %% not working
>        {Prefix,Url}={"xml_schema","http://www.w3.org/2001/XMLSchema.xsd"},
>    %% working
>    %% {Prefix,Url}={"soap_envelope","
> http://schemas.xmlsoap.org/soap/envelope/"},
>        inets:start(),
>    FileName = filename:join([filename:dirname(code:which(?MODULE)),
> Prefix]),
>        {ok, {{"HTTP/1.1", 200, "OK"}, _HeadRcv, Body}} = http:request(Url),
>        file:write_file(FileName++".xsd", list_to_binary(Body)),
>        erlsom:write_xsd_hrl_file(FileName++".xsd", FileName++".hrl").
>
> %%
> %% Local Functions
> %%
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090520/34e2a85a/attachment.htm>


More information about the erlang-questions mailing list