Hi Herong,

On Thu, Jun 18, 2020 at 12:29 PM Herong Yang <herong_y...@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

Reply via email to