RE: XML Schema validation doesnt throw some basic errors?

Kay,

In my reply before I was expecting an error which says "Element2 and 
Element1  are missing" and not just Element1. Sorry for the typo :-) As 
you can see from the error message that there is no mention of Element2. 

Also,  in the example you have given, though I get 2 errors, again there 
is no mention of Element2 in error for first <Data>  and no mention of 
Element2 and Element3 in the error for second Data element. 
1) Message=cvc-complex-type.2.4.a: Invalid content was found starting with 
element
'Element3'. One of '{Element1}' is expected.
2)  Message=cvc-complex-type.2.4.a: Invalid content was found starting 
with element
 'Element4'. One of '{Element1}' is expected.

As you said, probably no processor would give that and I guess I'll have 
to do a additional check on the elements present somehow withou usingt the 
schema.
Thanks for the help.

Let me ask you another question.
Though org.xml.sax. ErrorHandler interface provides a methods which 
provides message description of the errors(plus line and column number), I 
would like to  get additional information like the tag name, user entered 
value and expected value where the error occurs. There is a class 
org.apache.xerces.impl.XMLErrorReporter which if I extend and register 
with the parser is capable of proving these additional information .  Is 
it recommened to use this class considering that xerces has a note saying 
"Usage of this class is not supported. It may be altered or removed at any 
time" ? If not,  is there any other standard api that would provide me 
this additional information? 


Thanks again
Manoj




   "Michael Kay" <mike@saxonica.com> 
   01/10/2007 05:38 PM

To
"'Manoj Madhavan'" <manoj_madhavan@freddiemac.com>
cc
<xmlschema-dev@w3.org>
Subject
RE: XML Schema validation doesnt throw some basic errors?






As I said before, I don't think any processor is going to give you more 
than one error message in respect of the content of a single element. You 
say that you want to see the message "Element1 is missing" and it seems to 
me that the error message you get does say that, though perhaps it also 
gives you extra information which you didn't want.
 
What happens if you have two elements in your document whose content is 
wrong? for example:
 
<?xml version="1.0"?> 
<test:Root xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:test="http://www.my.com/test" 
           xs:schemaLocation="http://www.my.com/test test.xsd"> 
        <Data> 
                <Element3>value2</Element3> 
        </Data> 
        <Data> 
                <Element4>value2</Element4> 
        </Data> 
</test:Root> 
 
I would think that in this case it is reasonable to expect two errors to 
be reported.
 
Michael Kay
http://www.saxonica.com/

From: Manoj Madhavan [mailto:manoj_madhavan@freddiemac.com] 
Sent: 10 January 2007 21:56
To: Michael Kay
Cc: xmlschema-dev@w3.org
Subject: RE: XML Schema validation doesnt throw some basic errors?


Thanks for your response Kay . 

1.  I am using xerces 2.9 and I can see that this version infact doesnt 
tell me the list of all missing elements instead as I mentioned before, it 
gives me only the first occurance. Agreed that the schema would be 
validated eventually if I trigger validation again and again, but I would 
like to see all errors at once so that fixing the instance document is 
less time consuming. What I see is that implementation doesnt do that by 
default. So  is there a way I can specify additional contraints in my 
schema(this could be something like specifying the minimum valid elements 
to be present for a instance document to be valid) to force the schema 
validations to fire for every element? 

For example. With the below  schema and xml, I would like to see an error 
saying "Element1 is missing". 
Currently when I run the test class I get only 1 error which is " 
Message=cvc-complex-type.2.4.a: Invalid content was found starting with 
element 
 'Element3'. One of '{Element1}' is expected." 

Schema: 
<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                      xmlns:test="http://www.my.com/test" 
                      targetNamespace="http://www.my.com/test" 
                      elementFormDefault="unqualified"> 
<xs:complexType name="DataType"> 
        <xs:sequence> 
                <xs:element name="Element1" type="xs:string"/>         
                <xs:element name="Element2" type="xs:string"/>         
        </xs:sequence> 
</xs:complexType> 
<xs:complexType name="RootType"> 
        <xs:sequence> 
                <xs:element name="Data" type="test:DataType" 
maxOccurs="unbounded"/> 
        </xs:sequence> 
</xs:complexType> 
<xs:element name="Root" type="test:RootType"/> 
</xs:schema>             
 
xml: 
<?xml version="1.0"?> 
<test:Root xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:test="http://www.my.com/test" 
           xs:schemaLocation="http://www.my.com/test test.xsd"> 
        <Data> 
                <Element3>value2</Element3> 
        </Data> 
</test:Root> 


2. Regarding the second point I mentioned, it was a mistake at my end. I 
could see that an error saying <junk> is not valid element.   


Thanks 
Manoj 



   "Michael Kay" <mike@saxonica.com> 
   01/10/2007 03:38 PM 


To
"'MM'" <manoj_madhavan@freddiemac.com>, <xmlschema-dev@w3.org> 
cc

Subject
RE: XML Schema validation doesnt throw some basic errors?








> 1) If a complex type has 10 elements which are defined as 
> mandatory in my schema. In my xml instance if I put only the 
> 10th element, on validating this against the schema, I get 
> only 1 error saying that 'found {10th element} while 
> expecting 9th element.
> It doent say that the other 8 elements were missing. I've 
> enabled full-schema-checking. I want to collect all errors at 
> one go and dont want to get one error at a time. Is there a 
> way to achieve this?

I would think it unlikely that any implementation will give you more that
one error message for a sequence of sibling elements that doesn't match 
the
content model of the parent element. But error reporting depends entirely 
on
the implementation so you would be better off asking on a product-specific
list.



> 2) If i put a junk element which is not at all defined in the 
> schema just before closing my <root> tag, the schem 
> validation doesnt catch this. For
> eg: in the below xml
> <root>
>   <element_defined_in_schema_1>..</element_defined_in_schema_1>
>   ....
>   ....
>   <element_not_defined_in_schema>junk</element_not_defined_in_schema>
> </root>
> 
> schema validation doesnt throw an error saying that 
> "element_not_defined_in_schema" is not a valid one.
> 

My instinct is to say: prove it. Given that you haven't shown us the
evidence (full schema and instance document), my guess is that it's more
likely you have made a mistake than that Xerces has got this wrong.

Michael Kay
http://www.saxonica.com/



Thanks
Manoj
703-388-7496 | 2N / U12A 


   "Michael Kay" <mike@saxonica.com> 
   01/10/2007 03:38 PM 


To
"'MM'" <manoj_madhavan@freddiemac.com>, <xmlschema-dev@w3.org> 
cc

Subject
RE: XML Schema validation doesnt throw some basic errors?








> 1) If a complex type has 10 elements which are defined as 
> mandatory in my schema. In my xml instance if I put only the 
> 10th element, on validating this against the schema, I get 
> only 1 error saying that 'found {10th element} while 
> expecting 9th element.
> It doent say that the other 8 elements were missing. I've 
> enabled full-schema-checking. I want to collect all errors at 
> one go and dont want to get one error at a time. Is there a 
> way to achieve this?

I would think it unlikely that any implementation will give you more that
one error message for a sequence of sibling elements that doesn't match 
the
content model of the parent element. But error reporting depends entirely 
on
the implementation so you would be better off asking on a product-specific
list.

> 2) If i put a junk element which is not at all defined in the 
> schema just before closing my <root> tag, the schem 
> validation doesnt catch this. For
> eg: in the below xml
> <root>
>   <element_defined_in_schema_1>..</element_defined_in_schema_1>
>   ....
>   ....
>   <element_not_defined_in_schema>junk</element_not_defined_in_schema>
> </root>
> 
> schema validation doesnt throw an error saying that 
> "element_not_defined_in_schema" is not a valid one.
> 

My instinct is to say: prove it. Given that you haven't shown us the
evidence (full schema and instance document), my guess is that it's more
likely you have made a mistake than that Xerces has got this wrong.

Michael Kay
http://www.saxonica.com/

Received on Wednesday, 10 January 2007 23:14:04 UTC