You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Herong Yang <he...@yahoo.com.INVALID> on 2020/06/18 06:58:51 UTC

XML Schema Validation Error Report

Hi, 
By default, Xerces2 only reports only the first invalid sub-element and skips other subsequent invalid siblings. Is the any way to set Xerces2 to report all invalid sub-elements?
Here is the sample XML: <?xml version="1.0"?><root> <X/> <A/> <Y/> <B/></root>
Here is the XML Schema: <?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="root"> <xs:complexType> <xs:all> <xs:element name="X" minOccurs="0"/> <xs:element name="Y" minOccurs="0"/> </xs:all> </xs:complexType> </xs:element></xs:schema>
Here is the Xerces2 validation output: [Error] simple_4.xml:4:6: cvc-complex-type.2.4.a: Invalid content was found starting with element 'A'. One of '{Y}' is expected.
I want to see both element 'A' and element 'B' being reported in the output. 
Thanks. 

Herong

Re: XML Schema Validation Error Report

Posted by Herong Yang <he...@yahoo.com.INVALID>.
Hi Mukul, 
Sure, a large of invalid elements could be a problem for error reporting. But there should be some standard ways to manage that situation. 
Thanks again for your response. 
Herong
    On Saturday, June 20, 2020, 12:13:44 PM GMT+8, Mukul Gandhi <mu...@apache.org> wrote:  
 
 Hi Herong,
On Fri, Jun 19, 2020 at 5:37 PM Herong Yang <he...@yahoo.com> wrote:
The current error report is clear and useful. But I still think it will be nice if both 'A' and 'B' are listed in the error report, since both of them are not expected to be there.

To have this facility, for XML Schema error reporting, I think we need to consider two extremes as follows:For your use case,At one side, if the number of XML sibling invalid elements are less then the error reporting improvements you're suggesting seems ok to me.On the other hand, if the number of XML sibling invalid elements are large (say couple of hundred or even thousands), then IMHO your suggested error reporting would not look ok.
 
-- 
Regards,
Mukul Gandhi
  

Re: XML Schema Validation Error Report

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Herong,

On Fri, Jun 19, 2020 at 5:37 PM Herong Yang <he...@yahoo.com> wrote:

> The current error report is clear and useful. But I still think it will be
> nice if both 'A' and 'B' are listed in the error report, since both of them
> are not expected to be there.
>

To have this facility, for XML Schema error reporting, I think we need to
consider two extremes as follows:
For your use case,
At one side, if the number of XML sibling invalid elements are less then
the error reporting improvements you're suggesting seems ok to me.
On the other hand, if the number of XML sibling invalid elements are large
(say couple of hundred or even thousands), then IMHO your suggested error
reporting would not look ok.



-- 
Regards,
Mukul Gandhi

Re: XML Schema Validation Error Report

Posted by Herong Yang <he...@yahoo.com.INVALID>.
Hi Mukul,
Thank you for your response and suggestion. The current error report is clear and useful. But I still think it will be nice if both 'A' and 'B' are listed in the error report, since both of them are not expected to be there.  
Herong
    On Friday, June 19, 2020, 2:47:09 PM GMT+8, Mukul Gandhi <mu...@apache.org> wrote:  
 
 Hi Herong,
On Thu, Jun 18, 2020 at 12:29 PM Herong Yang <he...@yahoo.com> wrote:

By default, Xerces2 only reports only the first invalid sub-element and skips other subsequent invalid siblings. Is the any way to set Xerces2 to report all invalid sub-elements?

I don't think that, what you're asking for is possible with Xerces-J.
Personally, I do find the error report you're getting with your XML and XSD document samples, from Xerces-J to be useful. 
Here is the sample XML: <?xml version="1.0"?><root> <X/> <A/> <Y/> <B/></root>
Here is the XML Schema: <?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="root"> <xs:complexType> <xs:all> <xs:element name="X" minOccurs="0"/> <xs:element name="Y" minOccurs="0"/> </xs:all> </xs:complexType> </xs:element></xs:schema>
Here is the Xerces2 validation output: [Error] simple_4.xml:4:6: cvc-complex-type.2.4.a: Invalid content was found starting with element 'A'. One of '{Y}' is expected.
I want to see both element 'A' and element 'B' being reported in the output.

For your requirements stated above, I could probably suggest the following XML Schema 1.1 document (which makes the intent of XML Schema logic more clear),
<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="root">      <xs:complexType>  <xs:sequence>    <xs:any processContents="skip" minOccurs="0" maxOccurs="2"/>  </xs:sequence>  <xs:assert test="if (count(*) = 0) then true() else                             if (count(*) = 1) then (*[1]/name() = ('X', 'Y')) else                             if (count(*) = 2) then ((*[1]/name() = 'X' and *[2]/name() = 'Y')                                                               or                                                             (*[1]/name() = 'Y' and *[2]/name() = 'X')) else                             false()"/>      </xs:complexType>   </xs:element>   </xs:schema>
 
-- 
Regards,
Mukul Gandhi
  

Re: XML Schema Validation Error Report

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Herong,

On Thu, Jun 18, 2020 at 12:29 PM Herong Yang <he...@yahoo.com> wrote:

By default, Xerces2 only reports only the first invalid sub-element and
> skips other subsequent invalid siblings. Is the any way to set Xerces2 to
> report all invalid sub-elements?
>

I don't think that, what you're asking for is possible with Xerces-J.

Personally, I do find the error report you're getting with your XML and XSD
document samples, from Xerces-J to be useful.


> Here is the sample XML:
> <?xml version="1.0"?>
> <root>
> <X/>
> <A/>
> <Y/>
> <B/>
> </root>
>
> Here is the XML Schema:
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="root">
> <xs:complexType>
> <xs:all>
> <xs:element name="X" minOccurs="0"/>
> <xs:element name="Y" minOccurs="0"/>
> </xs:all>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> Here is the Xerces2 validation output:
> [Error] simple_4.xml:4:6: cvc-complex-type.2.4.a: Invalid content was
> found starting with element 'A'. One of '{Y}' is expected.
>
> I want to see both element 'A' and element 'B' being reported in the
> output.
>

For your requirements stated above, I could probably suggest the following
XML Schema 1.1 document (which makes the intent of XML Schema logic more
clear),

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

   <xs:element name="root">
      <xs:complexType>
<xs:sequence>
   <xs:any processContents="skip" minOccurs="0" maxOccurs="2"/>
</xs:sequence>
<xs:assert test="if (count(*) = 0) then true() else
                            if (count(*) = 1) then (*[1]/name() = ('X',
'Y')) else
                            if (count(*) = 2) then ((*[1]/name() = 'X' and
*[2]/name() = 'Y')
                                                              or
                                                            (*[1]/name() =
'Y' and *[2]/name() = 'X')) else
                            false()"/>
      </xs:complexType>
   </xs:element>

</xs:schema>



-- 
Regards,
Mukul Gandhi