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 Vinícius Lopes <vi...@gmail.com> on 2014/02/28 19:42:21 UTC

Retrieving all assertions made

Hello, I'd like to know if it is possible to retrieve the number of all
assertions that were made during the validation phase. Exteding the
DefaultHandler class, I'm able to retrieve the number of errors that have
occurred and parse the string to see if the error corresponds to an
assertion, but I'd like to know if there is any way in the API where I
could retrieve all assertions that were validated and didn't raise an
error. I know that I could do it manually by opening the XSD and checking
for the number of assertions that are made inside each tag, for example, by
using the XSD, I know that an element <X> have Y assertions. Then, if my
XML have a number N of <X>, I know that the total number of assertions is
N*Y. So, for knowing the number of valid assertions that were made, I
should only do N*Y - E, where E is the number of assertions errors that
were retrieved by the class that extends DefaultHandler. But I do not know
if there is a class in Xerces where I could read the XSD and retrieve this
kind of information from the XML, I also do not know if there is a class in
Xerces where I could check every element that is validated, not only those
that issues an error.

Thanks for the help.

Best regards,
                    Vinícius

Re: Retrieving all assertions made

Posted by Mukul Gandhi <mu...@apache.org>.
With Xerces's PSVI API implementation, we can fetch some of the information
you've asked. Here's a small Xerces PSVI code fragment for assertions
present on XSD complex types,

String xmlFile = "test1.xml";
String schemaPath = "test1.xsd";
Schema schema = schemaFactory.newSchema(new StreamSource(schemaPath));
Validator validator = schema.newValidator();
PSVIDocumentImpl resultDoc = new PSVIDocumentImpl();
validator.validate(new DOMSource(getDomDocument(xmlFile)), new
DOMResult(resultDoc));
PSVIElementNSImpl psviElement =
(PSVIElementNSImpl)(resultDoc.getElementsByTagName("Y")).item(0);
XSComplexTypeDefinition typeDefn =
(XSComplexTypeDefinition)psviElement.getTypeDefinition();
XSObjectList xsList = typeDefn.getAssertions();

This gives us, the <assert> elements present within an XSD document's
complex type.

I think, the current Xerces API cannot tell on which XML instance elements
(or on how many elements) the assertions have passed. As you've probably
found, Xerces API only can tell the list of failed assertions on an element
instance. I think, this is the only conformance level specified by the XSD
1.1 language for assert PSVI information.


On 1 March 2014 00:12, Vinícius Lopes <vi...@gmail.com>wrote:

> Hello, I'd like to know if it is possible to retrieve the number of all
> assertions that were made during the validation phase. Exteding the
> DefaultHandler class, I'm able to retrieve the number of errors that have
> occurred and parse the string to see if the error corresponds to an
> assertion, but I'd like to know if there is any way in the API where I
> could retrieve all assertions that were validated and didn't raise an
> error. I know that I could do it manually by opening the XSD and checking
> for the number of assertions that are made inside each tag, for example, by
> using the XSD, I know that an element <X> have Y assertions. Then, if my
> XML have a number N of <X>, I know that the total number of assertions is
> N*Y. So, for knowing the number of valid assertions that were made, I
> should only do N*Y - E, where E is the number of assertions errors that
> were retrieved by the class that extends DefaultHandler. But I do not know
> if there is a class in Xerces where I could read the XSD and retrieve this
> kind of information from the XML, I also do not know if there is a class in
> Xerces where I could check every element that is validated, not only those
> that issues an error.
>
> Thanks for the help.
>
> Best regards,
>                     Vinícius
>
>
>


> Regards,
> Mukul Gandhi
>