xerces schema validation: funny minOccurs behaviour

M

mstilli

Hi,

I am trying to use schema for server side validation using xerces to
catch the validation errors.

validating this XML:

<Content4>
<textarea13></textarea13>
<binaryobject3></binaryobject3>
</Content4>

against this schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsd:element name="Content4" type="contentType"/>

<xsd:complexType name="contentType">
<xsd:sequence>
<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
<xsd:element minOccurs="1" name="text16" type="text16"/>
<xsd:element name="textarea13" type="textarea13"/>
<xsd:element minOccurs="0" name="binaryobject3"
type="binaryobject3"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="text16">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>

<xsd:simpleType name="textarea13">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="binaryobject3">
<xsd:attribute name="filename"/>
</xsd:complexType>

<xsd:complexType name="metainfo">
<xsd:sequence>
<xsd:any maxOccurs="unbounded" minOccurs="0"
processContents="skip"/>
</xsd:sequence>
<xsd:anyAttribute processContents="skip"/>
</xsd:complexType>

</xsd:schema>

output these messages:

cvc-complex-type.2.4.a: Invalid content was found starting with
element 'textarea13'.
One of '{metainfo, text16}' is expected.
-------------^

This message seems to me a little wrong, given

<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
----------------------------------------^

Perhaps I'm missing something, but as far as I understood, if this
atribute value is set to 0 the element is *optional*, thus can't figure
why xerces doesn't discriminate and report "one of those is expected".

I would expect it to report only about the mandatory element(s)
missing, and not the whole sequence...

I googled this but found nothing. Am I missing something?




The other messages are just as expected...

cvc-minLength-valid: Value '' with length = '0' is not facet-valid with
respect to minLength '1' for type 'textarea13'.
cvc-type.3.1.3: The value '' of element 'textarea13' is not valid.

Thanks

marcello stillitano
 
G

George Bina

Hi,

Xerces does not tell you that you *must* enter metainfo, it just says
that it expects to find one of those elements at that position in the
document.

Best Regards,
George
 
M

Martin Honnen

validating this XML:

<Content4>
<textarea13></textarea13>
<binaryobject3></binaryobject3>
</Content4>

against this schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsd:element name="Content4" type="contentType"/>

<xsd:complexType name="contentType">
<xsd:sequence>
<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
<xsd:element minOccurs="1" name="text16" type="text16"/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Where is the text16 element for that you specify minOccurs="1"?
<xsd:element name="textarea13" type="textarea13"/>
output these messages:

cvc-complex-type.2.4.a: Invalid content was found starting with
element 'textarea13'.
One of '{metainfo, text16}' is expected.
-------------^

This message seems to me a little wrong, given

<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
----------------------------------------^

Perhaps I'm missing something, but as far as I understood, if this
atribute value is set to 0 the element is *optional*, thus can't figure
why xerces doesn't discriminate and report "one of those is expected".

The parser only knows that metainfo is possible and that text16 is
mandatory in the sequence so it tells you what might appear before the
textarea13 element.
 
M

Martin Honnen

that is the point, I would expect a message for text16 *only*

I don't see anything wrong, if you had maxOccurs="0" on metainfo then it
would not be possible but with the schema you have presented the
sequence before textarea13 could have a metainfo element occuring once.
 
M

mstilli

Hi,

I'm not sure if google posted my reply so I'll post again...

My understanding of "minOccurs" set to 0 is that the element in the
sequence colud be present or could be not , hence I would expect the
validation not to mention it.

Suppose to have a schema with a sequence of, say, twelve element in
wich only one of them is mandatory, once I validate some xml with no
elemet at all against it I get a message like "in your sequence one of
this twelve element is needed"

Perhaps returning a message like "look, in your sequence this mandatory
element is missing" isn't Xerces job, but that is what I would expect.

I'm using schema to server validate some values, and being able to tell
*exactly* what of those is not conformant with the schema iteslf I
found to be a generally well accomplished task with Xerces, but not in
this case.

Thanks

ciao

marcello stillitano
 
M

mstilli

[I messed with the reply option replying you privately, so I'll repost
all the mailing here. Sorry for that!]

Hi George,
No, that is not correct, look again, the message points you clearly that
the wrong element is textarea13, see: "Invalid content was found
starting with element 'textarea13'." and the error location info point
you also to the textarea13 element.

well, validating this xml:

<Content4>
<textarea13></textarea13>
<binaryobject3></binaryobject3>
</Content4>

against this schema:

<xsd:element name="Content4" type="contentType"/>
<xsd:complexType name="contentType">
<xsd:sequence>
<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
<xsd:element minOccurs="1" name="text16" type="text16"/>
<xsd:element name="textarea13" type="textarea13"/>
<xsd:element minOccurs="0" name="binaryobject3"
type="binaryobject3"/>
</xsd:sequence>
</xsd:complexType>
....follow definitions...[2]

I get this message:

cvc-complex-type.2.4.a: Invalid content was found starting with
element 'textarea13'.
-------------^
It's fine by Xerces to acknoledge me of that, but it's a bit
redundant[1].

One of '{metainfo, text16}' is expected.
-------------^
While here it is not discriminating at all between the missing
mandatory element and the optional ones... and BTW why binaryobject3
isn't in the list? How could I find out what of the mandatory elements
is missing?

If I have to acknowledge an user like "you did not provide these
*mandatory* informations, please fill *these* fields and submit again"
Where do I get from that message *only* the mandatory elements needed?


[1] the rest of the message:
cvc-minLength-valid: Value '' with length = '0' is not facet-valid
with respect to minLength '1' for type 'textarea13'.
cvc-type.3.1.3: The value '' of element 'textarea13' is not valid.
However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.

I'm saying it could be done a bit better *but* from my very point of
view... I'm not very sure were to submit this request, is it that the
right place? : http://forum.java.sun.com/thread.jspa?
forumID=17&threadID=564284

If is not and if you know where, could you please provide me the where
to post my doubts / requests?

Thank you very much!

ciao

marcello

Hi Marcello,
> Sorry but I still don't get the point of such message... It gives me not
> actually any clue of the "wrong" elements, it just brings to my
> attention that "something is wrong there".


No, that is not correct, look again, the message points you clearly
that
the wrong element is textarea13, see: "Invalid content was found
starting with element 'textarea13'." and the error location info point
you also to the textarea13 element.

IMO Xerces gives a good error message and as a user I prefer this
message instead of something as you propose. However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.

> p.s. Why don't we keep this discussion public? I googled extensively
> this topic and found really few, guess other devs could find those
> informations very useful!


I did not made the discussion private, you did, you replied to me
personally - I always use reply to all and I remember I double checked
in this case if you sent the message only to me or also to the list.

Fell free to post our discussion back to the list.


Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina

<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com



- Show quoted text -
marcello said:
Hi George,

Sorry for the great delay of this the reply but I rarely use this account..

Xerces already gives in facet validation two messages (each one related
to the relative specification) so it could keeping giving the
same message AND another one enlisting-highlighting just the mandatory
ones, no matter of their position in the sequence, because the same
message is also displayied using the "all" statament, thus no
specific order is given.

My utopian message would be very cheap to achieve, that would just tell
me that some of the expected mandatory elements are missing, no matter
their position in the sequence, just: "look, this schema expect those
elements to be in place because their minoccurs attribute is greater
than zero, those others instead are optionals"

I know schema is more a "structure" validator than a "content"
one, but in this specific case I can't onestly see the use of that
message...

"Imagine that you edit the document. It is better to get in the error
message all the elements that can be inserted at that position..."

Sorry but I still don't get the point of such message... It gives me not
actually any clue of the "wrong" elements, it just brings to my
attention that "something is wrong there".

thanks and excuse me again for the delay!

ciao,

Marcello

p.s. Why don't we keep this discussion public? I googled extensively
this topic and found really few, guess other devs could find those
informations very useful!


On 1/24/07, *George Cristian Bina* <[email protected]
 
G

George Bina

Hi Marcelo,
One of '{metainfo, text16}' is expected.
-------------^
While here it is not discriminating at all between the missing
mandatory element and the optional ones... and BTW why binaryobject3
isn't in the list? How could I find out what of the mandatory elements
is missing?

The binaryobject3 is not allowed at that position in the document, in
the same way as textare13 is not allowed, that is why the element is
not in the list.
I'm not very sure were to submit this request, is it that the
right place? :http://forum.java.sun.com/thread.jspa?
forumID=17&threadID=564284

If is not and if you know where, could you please provide me the where
to post my doubts / requests?

See
http://xerces.apache.org/xerces2-j/jira.html
I suggest you should write first to the (e-mail address removed)
list as the page suggests.

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

[I messed with the reply option replying you privately, so I'll repost
all the mailing here. Sorry for that!]

Hi George,
No, that is not correct, look again, the message points you clearly that
the wrong element is textarea13, see: "Invalid content was found
starting with element 'textarea13'." and the error location info point
you also to the textarea13 element.well, validating this xml:

<Content4>
<textarea13></textarea13>
<binaryobject3></binaryobject3>
</Content4>

against this schema:

<xsd:element name="Content4" type="contentType"/>
<xsd:complexType name="contentType">
<xsd:sequence>
<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
<xsd:element minOccurs="1" name="text16" type="text16"/>
<xsd:element name="textarea13" type="textarea13"/>
<xsd:element minOccurs="0" name="binaryobject3"
type="binaryobject3"/>
</xsd:sequence>
</xsd:complexType>
...follow definitions...[2]

I get this message:

cvc-complex-type.2.4.a: Invalid content was found starting with
element 'textarea13'.
-------------^
It's fine by Xerces to acknoledge me of that, but it's a bit
redundant[1].

One of '{metainfo, text16}' is expected.
-------------^
While here it is not discriminating at all between the missing
mandatory element and the optional ones... and BTW why binaryobject3
isn't in the list? How could I find out what of the mandatory elements
is missing?

If I have to acknowledge an user like "you did not provide these
*mandatory* informations, please fill *these* fields and submit again"
Where do I get from that message *only* the mandatory elements needed?

[1] the rest of the message:
cvc-minLength-valid: Value '' with length = '0' is not facet-valid
with respect to minLength '1' for type 'textarea13'.
cvc-type.3.1.3: The value '' of element 'textarea13' is not valid.
However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.I'm saying it could be done a bit better *but* from my very point of
view... I'm not very sure were to submit this request, is it that the
right place? :http://forum.java.sun.com/thread.jspa?
forumID=17&threadID=564284

If is not and if you know where, could you please provide me the where
to post my doubts / requests?

Thank you very much!

ciao

marcello

Hi Marcello,
Sorry but I still don't get the point of such message... It gives me not
actually any clue of the "wrong" elements, it just brings to my
attention that "something is wrong there".

No, that is not correct, look again, the message points you clearly
that
the wrong element is textarea13, see: "Invalid content was found
starting with element 'textarea13'." and the error location info point
you also to the textarea13 element.

IMO Xerces gives a good error message and as a user I prefer this
message instead of something as you propose. However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.
p.s. Why don't we keep this discussion public? I googled extensively
this topic and found really few, guess other devs could find those
informations very useful!

I did not made the discussion private, you did, you replied to me
personally - I always use reply to all and I remember I double checked
in this case if you sent the message only to me or also to the list.

Fell free to post our discussion back to the list.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina

<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debuggerhttp://www.oxygenxml.com

- Show quoted text -



marcello said:
Hi George,
Sorry for the great delay of this the reply but I rarely use this account..
Xerces already gives in facet validation two messages (each one related
to the relative specification) so it could keeping giving the
same message AND another one enlisting-highlighting just the mandatory
ones, no matter of their position in the sequence, because the same
message is also displayied using the "all" statament, thus no
specific order is given.
My utopian message would be very cheap to achieve, that would just tell
me that some of the expected mandatory elements are missing, no matter
their position in the sequence, just: "look, this schema expect those
elements to be in place because their minoccurs attribute is greater
than zero, those others instead are optionals"
I know schema is more a "structure" validator than a "content"
one, but in this specific case I can't onestly see the use of that
message...
"Imagine that you edit the document. It is better to get in the error
message all the elements that can be inserted at that position..."
Sorry but I still don't get the point of such message... It gives me not
actually any clue of the "wrong" elements, it just brings to my
attention that "something is wrong there".
thanks and excuse me again for the delay!


p.s. Why don't we keep this discussion public? I googled extensively
this topic and found really few, guess other devs could find those
informations very useful!
On 1/24/07, *George Cristian Bina* <[email protected]
<mailto:[email protected]>> wrote:
Hi Marcello,
If the error message would have contained only mandatory elements then
people will complain why the parser says so, because the element x
which
is optional is perfectly ok at that position so the parser should expect
to see that as well as the mandatory elements.
The perfect but utopian message would be to enumerate all the possible
combinations that can appear at that location. That's clearly
practically impossible due to the very large number of possible
combinations so Xerces just shows all the elements that can be inserted
further to create valid content.
Imagine that you edit the document. It is better to get in the error
message all the elements that can be inserted at that position instead
of getting only the required elements as in that way you have more
information how to continue your editing, what elements you can insert
there and keep the document valid.
 
M

mstilli

thanks!

ciao

marcello

Hi Marcelo,
One of '{metainfo, text16}' is expected.
-------------^
While here it is not discriminating at all between the missing
mandatory element and the optional ones... and BTW why binaryobject3
isn't in the list? How could I find out what of the mandatory elements
is missing?The binaryobject3 is not allowed at that position in the document, in
the same way as textare13 is not allowed, that is why the element is
not in the list.
I'm not very sure were to submit this request, is it that the
right place? :http://forum.java.sun.com/thread.jspa?
forumID=17&threadID=564284
If is not and if you know where, could you please provide me the where
to post my doubts / requests?Seehttp://xerces.apache.org/xerces2-j/jira.html
I suggest you should write first to the (e-mail address removed)
list as the page suggests.

Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debuggerhttp://www.oxygenxml.com

[I messed with the reply option replying you privately, so I'll repost
all the mailing here. Sorry for that!]
Hi George,

against this schema:
<xsd:element name="Content4" type="contentType"/>
<xsd:complexType name="contentType">
<xsd:sequence>
<xsd:element minOccurs="0" name="metainfo" type="metainfo"/>
<xsd:element minOccurs="1" name="text16" type="text16"/>
<xsd:element name="textarea13" type="textarea13"/>
<xsd:element minOccurs="0" name="binaryobject3"
type="binaryobject3"/>
</xsd:sequence>
</xsd:complexType>
...follow definitions...[2]
I get this message:
cvc-complex-type.2.4.a: Invalid content was found starting with
element 'textarea13'.
-------------^
It's fine by Xerces to acknoledge me of that, but it's a bit
redundant[1].
One of '{metainfo, text16}' is expected.
-------------^
While here it is not discriminating at all between the missing
mandatory element and the optional ones... and BTW why binaryobject3
isn't in the list? How could I find out what of the mandatory elements
is missing?
If I have to acknowledge an user like "you did not provide these
*mandatory* informations, please fill *these* fields and submit again"
Where do I get from that message *only* the mandatory elements needed?
[1] the rest of the message:
cvc-minLength-valid: Value '' with length = '0' is not facet-valid
with respect to minLength '1' for type 'textarea13'.
cvc-type.3.1.3: The value '' of element 'textarea13' is not valid.
However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.I'm saying it could be done a bit better *but* from my very point of
view... I'm not very sure were to submit this request, is it that the
right place? :http://forum.java.sun.com/thread.jspa?
forumID=17&threadID=564284
If is not and if you know where, could you please provide me the where
to post my doubts / requests?
Thank you very much!


Hi Marcello,
No, that is not correct, look again, the message points you clearly
that
the wrong element is textarea13, see: "Invalid content was found
starting with element 'textarea13'." and the error location info point
you also to the textarea13 element.
IMO Xerces gives a good error message and as a user I prefer this
message instead of something as you propose. However, if you feel very
strongly that this is wrong then I would suggest opening a request for
enhancement on Xerces Jira and the Xerces developers will have their
take on this issue.
I did not made the discussion private, you did, you replied to me
personally - I always use reply to all and I remember I double checked
in this case if you sent the message only to me or also to the list.
Fell free to post our discussion back to the list.
Best Regards,
George
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debuggerhttp://www.oxygenxml.com
- Show quoted text -

leggi tutto- Nascondi testo tra virgolette -- Mostra testo tra virgolette -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top