Erlang/OTP Forums

Author Message

<  Erlang  ~  Erlsom - new version supports xml schema almost 100%

Willem
Posted: Fri Jul 21, 2006 7:20 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
Hi,

I put a new version of Erlsom on sourceforge:
http://sourceforge.net/projects/erlsom

Erlsom is a set of functions to deal with XML Schema (XSDs) in Erlang. First you 'compile' the schema, and after that you can parse XML documents that conform to the schema. The result is a structure of Erlang records, based on the types that are defined by the Schema. Or, the other way around, a structure of records can be translated to an XML document. "XML to Erlang binding"!

In this version I added support for attribute groups, global attribute definitions, and mixed types. I also improved the support for 'any' types, and I fixed quite a few bugs.

The tool as it is now can deal with almost the complete XML Schema spec. (It doesn't support redefines and substition groups, and it doesn't check things like identity constraints).

I'd appreciate your feedback... I've posted a few earlier versions, but so far I haven't received many comments. I'd be happy to turn this into a really useful tool (in fact, I hope that this version is useful), but I need your input.

Regards,
Willem
View user's profile Send private message
Heinrich
Posted: Fri Aug 11, 2006 1:31 pm Reply with quote
Joined: 11 Aug 2006 Posts: 4 Location: Midrand, South Africa
I tried erlsom again on the WSDL XSD, but no luck Smile

It seems to choke on the following

Code:

  <!-- description element decl and type def -->
  <xs:element name="description" type="wsdl:DescriptionType">
    <xs:unique name="interface">
      <xs:selector xpath="wsdl:interface"/>
      <xs:field xpath="@name"/>
    </xs:unique>
    <xs:unique name="binding">
      <xs:selector xpath="wsdl:binding"/>
      <xs:field xpath="@name"/>
    </xs:unique>
    <xs:unique name="service">
      <xs:selector xpath="wsdl:service"/>
      <xs:field xpath="@name"/>
    </xs:unique>
  </xs:element>

_________________
-]-[
View user's profile Send private message
Willem
Posted: Fri Aug 11, 2006 3:57 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
I don't know - it seems to work on my PC.

I can compile the WSDL schema found here: http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd. Is this the file you are trying to process?

Can you give me some background: what error message do you get, what environment are you on, what version of erlsom are you using?

Note: you are obviously trying to use erlsom as a way to implement SOAP. This is a very good idea - I will try to do it myself as well, and I believe that it will work - let's see who gets there first. However, there is a complication: In order to parse a complete WSDL file, you must not only compile the schema for WSDL, but also the schema for XML Schema. This won't work with the current version of erlsom - there is a problem with the namespaces. The fact that the thing you are compiling is from the same namespace as the language that is used for the definition is a bit too much.

Obviously erlsom *can* parse elements from the XSD-namespace - that is the whole point of the software. It just doesn't use a 'compiled xsd-xsd' to parse the xsd, but it uses an internal 'model'. The challenge is to implement a feature that makes erlsom use its internal model whenever it finds an element from the XSD-namespace inside an XML document (provided that it is allowed at that location - it would have to be within an 'any'-element).

(I am sorry if this is confusing, but I don't know how to explain it better)


Heinrich wrote:
I tried erlsom again on the WSDL XSD, but no luck Smile

It seems to choke on the following

Code:

  <!-- description element decl and type def -->
  <xs:element name="description" type="wsdl:DescriptionType">
    <xs:unique name="interface">
      <xs:selector xpath="wsdl:interface"/>
      <xs:field xpath="@name"/>
    </xs:unique>
    <xs:unique name="binding">
      <xs:selector xpath="wsdl:binding"/>
      <xs:field xpath="@name"/>
    </xs:unique>
    <xs:unique name="service">
      <xs:selector xpath="wsdl:service"/>
      <xs:field xpath="@name"/>
    </xs:unique>
  </xs:element>
[url][/url]


Last edited by Willem on Mon Aug 14, 2006 7:47 pm; edited 1 time in total
View user's profile Send private message
Willem
Posted: Mon Aug 14, 2006 7:44 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
Hm, I guess you were looking at the XSD for WSDL v. 2.0. This didn't work. I fixed a few things and posted version Erlsom 0.0.5.
View user's profile Send private message
rvg
Posted: Tue Aug 29, 2006 1:12 pm Reply with quote
User Joined: 29 Aug 2006 Posts: 27
Hey there Willem and Mr. H...

Quick question - when you build tools like this, do you write proper test cases? I.e. if someone starts to use this code, how can we be sure that it will work after a change?
View user's profile Send private message Visit poster's website
Willem
Posted: Sun Sep 10, 2006 10:54 am Reply with quote
User Joined: 21 Jul 2006 Posts: 59
rvg wrote:
Hey there Willem and Mr. H...

Quick question - when you build tools like this, do you write proper test cases? I.e. if someone starts to use this code, how can we be sure that it will work after a change?


sorry for the slow response, I have been on vacation

Yes, of course. To test Erlsom I have a fairly large set of XSDs and conforming/non-conforming XML documents, and a simple program to run the whole batch. (I added the XSD for WSDL 2.0 to the set, thanks to Heinrichs remark.)

If I get around writing support for SOAP I will obviously need a test framework as well - this is likely to be a bit more complicated.

Regards,
Willem
View user's profile Send private message
Willem
Posted: Sun Sep 10, 2006 10:54 am Reply with quote
User Joined: 21 Jul 2006 Posts: 59
rvg wrote:
Hey there Willem and Mr. H...

Quick question - when you build tools like this, do you write proper test cases? I.e. if someone starts to use this code, how can we be sure that it will work after a change?


sorry for the slow response, I have been on vacation

Yes, of course. To test Erlsom I have a fairly large set of XSDs and conforming/non-conforming XML documents, and a simple program to run the whole batch. (I added the XSD for WSDL 2.0 to the set, thanks to Heinrichs remark.)

If I get around writing support for SOAP I will obviously need a test framework as well - this is likely to be a bit more complicated.

Regards,
Willem
View user's profile Send private message
datacompboy
Posted: Thu Sep 21, 2006 2:56 am Reply with quote
User Joined: 21 Sep 2006 Posts: 69 Location: Novosibirsk, Russia
Willem wrote:
If I get around writing support for SOAP I will obviously need a test framework as well - this is likely to be a bit more complicated.


There some strange thing.

I have compiled soap_encoding.xml (Schema for the SOAP/1.1 encoding), compiled wsdl.xml (2003-02-11.xsd) -- everything compiled fine.

Then try to parse WSDL from old service originally written in C#.
It parse everything, except of inner <types> !
<types> come empty, but <message>'s, <portType>'s, <binding>'s, <service> -- parsed fine.

If I extranct <types> into different file, it parses as default XSD fine.

What's wrong?

Also, how I can convert parsed xsd to model?
So just parse WSDL, convert Types to model, and use Messages and Ports to serve WS.

p.s.: I have create new post in forum for erlang+soap -- erlsoap 0.4, that uses your erlsom for operation. Since I have no luck with full WSDL parse, I have just use only XSD with records operations in service handlers. If you describe how to create model from parsed <types> -- i'll update samples and framework.

_________________
--- suicide proc near\n call death\n suicide endp
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
francesco
Posted: Thu Sep 21, 2006 8:57 am Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
Heinrich was asking about erlang and soap in another forum. He might be interested in what you are doing...

http://forum.trapexit.org/viewtopic.php?t=5946

Francesco
View user's profile Send private message Visit poster's website
Willem
Posted: Thu Sep 21, 2006 5:56 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
datacompboy wrote:
Willem wrote:
If I get around writing support for SOAP I will obviously need a test framework as well - this is likely to be a bit more complicated.


There some strange thing.

I have compiled soap_encoding.xml (Schema for the SOAP/1.1 encoding), compiled wsdl.xml (2003-02-11.xsd) -- everything compiled fine.

Then try to parse WSDL from old service originally written in C#.
It parse everything, except of inner <types> !
<types> come empty, but <message>'s, <portType>'s, <binding>'s, <service> -- parsed fine.

If I extranct <types> into different file, it parses as default XSD fine.

What's wrong?

Also, how I can convert parsed xsd to model?
So just parse WSDL, convert Types to model, and use Messages and Ports to serve WS.

p.s.: I have create new post in forum for erlang+soap -- erlsoap 0.4, that uses your erlsom for operation. Since I have no luck with full WSDL parse, I have just use only XSD with records operations in service handlers. If you describe how to create model from parsed <types> -- i'll update samples and framework.


The reason that you don't see the types is because you would have to add the XSD for XML Schema to the (compiled) schema for WSDL. However, that won't work, since erlsom doesn't accept the XSD for XML Schema. It gets confused, because the XSD namepace is used in two ways: (a) to describe the target namespace, and (b) as the target namespace itself.

Additionally, the output wouldn't be what you want: it would be a set of records that describe the types, but it wouldn't be a 'compiled schema'. You would still have to compile it.

To solve this, 2 undocumented functions are available in erlsom.
- erlsom:add_xsd_model()
- erlsom_compile:compile_parsed_xsd()

The procedure is as follows.
1. compile wsdl.xsd
2. add_xsd_model
3. parse your wsdl file
4. get the 'types' element out of the parsing results
5. apply erlsom_compile:compile_parsed_xsd to the types

Good luck!

(Thanks for pointing out the error in erlsom_write(). I will fix it. I have fixed a few other bugs as well - I hope to post a new version some time this weekend.)
View user's profile Send private message
tobbe
Posted: Wed Nov 08, 2006 10:20 am Reply with quote
User Joined: 19 Jan 2005 Posts: 274 Location: Stockholm, Sweden
Hi,

I have a WSDL and are following datacowboy's description on how to get erlsom to generate an .hrl header file. However, it chokes on the following construct:

Code:

<xsd:element minOccurs="0" maxOccurs="1" name="HitListCompanyResult">
  <xsd:complexType mixed="true">
    <xsd:sequence>
      <xsd:any/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>


...and displays the following error message: Mixed only supported for elements with maxOccurs > 1

I'm not good at this so if someone who is, could explain if my schema is wrong or if erlsom is at fault, it would be appreciated.

Also, I fixed some code in erlsom.erl:

Code:

write_hrl_file(Xsd, Prefix, Namespaces, Output) ->
  case file:read_file(Xsd) of
    {ok, Bin} ->
      Res = erlsom_writeHrl:writeHrlFile(erlsom_lib:toUnicode(Bin), Prefix, Namespaces),
      case Res of
     {error, _} = Error -> Error;
     Hdr                -> file:write_file(Output, ucs:to_utf8(Hdr))
      end;
    Error ->
      Error
  end.


Cheers, Tobbe
View user's profile Send private message Send e-mail Visit poster's website
Willem
Posted: Thu Nov 09, 2006 8:01 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
Hi Tobbe,

The xsd snippet is correct, but Erlsom cannot handle it (this is one of the limitations listed in the documentation).

The reason is:
- it wasn't clear to me how to map such an xml structure to a record structure
- this is an unusual pattern.

The xsd as you have descriped it, means that HitListCompanyResult should consist of: an optional bit of text, exactly one element of any type, and finally an optional bit of text.

A much more usual pattern is (from the WSDL xsd):

Code:

 <xs:complexType mixed="true" name="tDocumentation" >
    <xs:sequence>
      <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />
    </xs:sequence>
  </xs:complexType>


Erlsom does know how to handle this.

Regards,
Willem


tobbe wrote:
Hi,

I have a WSDL and are following datacowboy's description on how to get erlsom to generate an .hrl header file. However, it chokes on the following construct:

Code:

<xsd:element minOccurs="0" maxOccurs="1" name="HitListCompanyResult">
  <xsd:complexType mixed="true">
    <xsd:sequence>
      <xsd:any/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>


...and displays the following error message: Mixed only supported for elements with maxOccurs > 1

I'm not good at this so if someone who is, could explain if my schema is wrong or if erlsom is at fault, it would be appreciated.

...

Cheers, Tobbe
View user's profile Send private message
daniello
Posted: Tue Apr 03, 2007 11:36 am Reply with quote
User Joined: 03 Apr 2007 Posts: 15
Hi I tried to compile schema got from http://schemas.xmlsoap.org/soap/encoding/ and saved as encoding.xsd but got the following:

4> erlsom:compile_xsd_file("encoding.xsd", []).
{error,"Group or anonymous sequence nested too deep"}


Can anybody help with this issue?

Kind Regards,
Daniello
View user's profile Send private message
Willem
Posted: Tue Apr 03, 2007 6:44 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
Hi,

The reason is probably that the XSD contains a group and an element with the same name ("Array"). The current version of erlsom doesn't handle that correctly.

In the version I am currently working on, this problem has been solved (together with quite a few other shortcomings). I hope to release it in a couple of weeks.

Note: if you want to use soap encoding (that is: write documents using the so called 'section 5' encoding rules), there is a lot more that you will have to do. Putting the encoding information into the document has nothing to do with XML schema as such, and Erlsom currently has no special support for this. Also the SOAP implementation that is provided with YAWS (based on Erlsom) only supports 'Literal' encoding.

daniello wrote:
Hi I tried to compile schema got from http://schemas.xmlsoap.org/soap/encoding/ and saved as encoding.xsd but got the following:

4> erlsom:compile_xsd_file("encoding.xsd", []).
{error,"Group or anonymous sequence nested too deep"}


Can anybody help with this issue?

Kind Regards,
Daniello
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum