[go: up one dir, main page]

Menu

Problem with "unbounded" maxOccurs elements

Help
JManuel
2007-09-21
2013-04-15
  • JManuel

    JManuel - 2007-09-21

    Hi,

    I've been using Erlsom for a while but today I found a strange behaviour. I'd like to know if it's just working as intended :)

    Let's suppose that we have the following elements (an extract of the complete XSD):

    <xsd:element name="output" type="xsd:string" minOccurs="0" maxOccurs="1"/>

    <xsd:element name="watch" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>

    If we try to parse this (partial) XML:

    <output/>
    <watch/>

    The result will be an atom 'undefined' for output BUT for watch the value will be [[]]. This behaviour will make erlsom to crash if you try to generate the same XML from the resultant record obtained from parsing:

    {badarg,[{erlang,hd,[[]]},
             {erlsom_write,processElementValues,6},
             {erlsom_write,struct2xml,5},
             {erlsom_write,processAlternativeValue,6},
             {erlsom_write,processElementValues,6},
             {erlsom_write,struct2xml,5},
             {erlsom_write,processAlternativeValue,6},
             {erlsom_write,processElementValues,6}]}

    So, I'd like to know if this is the expected behaviour in these cases and I'd have to "clean up" those records before calling the erlsom:write method with it.

    Thank you :)

     
    • Willem de Jong

      Willem de Jong - 2007-09-21

      Hi,

      This is not intended. I'll have a look at it.

      Regards, Willem

       
    • Willem de Jong

      Willem de Jong - 2007-09-22

      When I tried I didn't find a problem with the decoding (so you shouldn't change the records, because they are correct), but there is a problem with erlsom_write.

      It can be fixed by replacing the lines 155, 156:

          case V1 of
            _ when is_list(V1) ->

      by:
          case V1 of
            [] -> %% "", string of 0 characters
              {listOfStrings, 1};
            _ when is_list(V1) ->

      (That is: adding two lines).

      I'll include this change in the next release, thanks for letting me know.

      Regarding the decoding:
      I created a minimal XML document that follows your description, and an XSD that matches it. The XML looks like this:
      <tag>
        <output/>
        <watch/>
      </tag>.

      The result of decoding this XML is {tag,[],[],[[]]}

      The first [] indicates that there are no 'special' atributes like xml:lang,
      the second [] indicates that the value of 'output' is a string of 0 chars,
      [[]] indicates that there is one 'watch' element, which has a string of 0 chars as its value.

      Note that the result can also be read as: {tag,[],"",[""]}

       
    • JManuel

      JManuel - 2007-09-24

      Thank you very much for your fast answer.

      I already fixed it and now everything works fine, thank you.

       

Log in to post a comment.