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 ZagZig <po...@web.de> on 2010/08/20 10:20:44 UTC

missing element name in validation result

Hello everyone,

i've a problem with the result of the validation. I validate my xml file
against a xsd and everything is working fine, except that i can't get the
name of the element that was not correctly filled. That means if i've an
empty element "id" in my xml, which is from type integer, the error message
i got is 

cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.

which is correct, but i would like to print out the name of the element with
the invalid value.

All information my errorhandler gives me are

publicId: null
systemId: null
line number: 33
column number: 22
localized message: cvc-datatype-valid.1.2.1: '' is not a valid value for
'integer'.
message: cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
toString(): org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is
not a valid value for 'integer'.

<code>
public class MyErrorHandler implements ErrorHandler {

	public void error(SAXParseException arg0) throws SAXException {
		System.out.println("publicId: " + arg0.getPublicId());
		System.out.println("systemId: " + arg0.getSystemId());
		System.out.println("line number: " + arg0.getLineNumber());
		System.out.println("column number: " + arg0.getColumnNumber());
		System.out.println("localized message: " + arg0.getLocalizedMessage());
		System.out.println("message: " + arg0.getMessage());
		System.out.println("toString(): " + arg0.toString());
		System.out.print("Parsing XML failed due to a:\n" +
arg0.getClass().getName());
		throw arg0;

	}

	public void fatalError(SAXParseException arg0) throws SAXException {
		System.out.println("publicId: " + arg0.getPublicId());
		System.out.println("systemId: " + arg0.getSystemId());
		System.out.println("line number: " + arg0.getLineNumber());
		System.out.println("column number: " + arg0.getColumnNumber());
		System.out.println("localized message: " + arg0.getLocalizedMessage());
		System.out.println("message: " + arg0.getMessage());
		throw arg0;

	}

	public void warning(SAXParseException arg0) throws SAXException {
		System.out.println("publicId: " + arg0.getPublicId());
		System.out.println("systemId: " + arg0.getSystemId());
		System.out.println("line number: " + arg0.getLineNumber());
		System.out.println("column number: " + arg0.getColumnNumber());
		System.out.println("localized message: " + arg0.getLocalizedMessage());
		System.out.println("message: " + arg0.getMessage());
		throw arg0;

	}

}
</code>

The element definition in the xsd is 

    <xs:element name="ID" type="ID" />

    <xs:simpleType name="ID">
        <xs:restriction base="xs:integer">
            <xs:totalDigits value="7" />
        </xs:restriction>
    </xs:simpleType>

Has somebody an idea how i can solve my problem?

Thanking you in advance for any help you can give me.

-- 
View this message in context: http://old.nabble.com/missing-element-name-in-validation-result-tp29489740p29489740.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: missing element name in validation result

Posted by Mukul Gandhi <mu...@apache.org>.
On Fri, Aug 20, 2010 at 5:54 PM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> "ElementPSVImpl" is an internal class. Developers should be using the API
> (i.e. ElementPSVI) [1].

Thanks, Michael.

And also for useful observations about SAXParseException, which I
think would solve the problem of OP in a SAX way.



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: missing element name in validation result

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
"ElementPSVImpl" is an internal class. Developers should be using the API
(i.e. ElementPSVI) [1].

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xs/org/apache/xerces/xs/ElementPSVI.html

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 08/20/2010 06:58:19 AM:

> Hi Lars,
>     I think it is possible with Xerces to get validation details you
> are seeking via PSVI objects.
>
> If you look at,
> http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/
> xerces/impl/xs/ElementPSVImpl.html
>
> you may for example use the getValidity() method of "ElementPSVImpl"
> to know if the element was determined to be valid or invalid after the
> validation episode.
>
> On Fri, Aug 20, 2010 at 2:43 PM, ZagZig <po...@web.de> wrote:
> > Thanks a lot Mukul. The problem is that the validation is on server
side and
> > if an element is missing or not valid, then i want to send a response
to the
> > client, that the element xy isn't valid. But if there is no way to get
the
> > element name by the sax exception i'll maybe parse the element by the
line
> > and column number out of the xml and send this and the exception back
as the
> > result.
> >
> > Best regards,
> > Lars.
>
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Re: missing element name in validation result

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Lars,
    I think it is possible with Xerces to get validation details you
are seeking via PSVI objects.

If you look at,
http://xerces.apache.org/xerces2-j/javadocs/xerces2/org/apache/xerces/impl/xs/ElementPSVImpl.html

you may for example use the getValidity() method of "ElementPSVImpl"
to know if the element was determined to be valid or invalid after the
validation episode.

On Fri, Aug 20, 2010 at 2:43 PM, ZagZig <po...@web.de> wrote:
> Thanks a lot Mukul. The problem is that the validation is on server side and
> if an element is missing or not valid, then i want to send a response to the
> client, that the element xy isn't valid. But if there is no way to get the
> element name by the sax exception i'll maybe parse the element by the line
> and column number out of the xml and send this and the exception back as the
> result.
>
> Best regards,
> Lars.



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: missing element name in validation result

Posted by ZagZig <po...@web.de>.


Mukul Gandhi-4 wrote:
> 
> On Fri, Aug 20, 2010 at 1:50 PM, ZagZig <po...@web.de> wrote:
>> cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
>>
>> which is correct, but i would like to print out the name of the element
>> with
>> the invalid value.
> 
>> line number: 33
>> column number: 22
> 
> you are using SAXParseException [1] class to retrieve error details
> (which we should). This also inherits methods from SAXException [2].
> 
> So we are limited to error information provided by these classes.
> 
> As far as your ability to point to the relevant places in XML or
> schema documents, I think line and column numbers should be
> sufficient.
> 
> [1]
> http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/SAXParseException.html
> [2]
> http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/SAXException.html
> 
> 
> 
> -- 
> Regards,
> Mukul Gandhi
> 

Thanks a lot Mukul. The problem is that the validation is on server side and
if an element is missing or not valid, then i want to send a response to the
client, that the element xy isn't valid. But if there is no way to get the
element name by the sax exception i'll maybe parse the element by the line
and column number out of the xml and send this and the exception back as the
result.

Best regards,
Lars.

-- 
View this message in context: http://old.nabble.com/missing-element-name-in-validation-result-tp29489740p29490134.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: missing element name in validation result

Posted by Mukul Gandhi <mu...@apache.org>.
On Fri, Aug 20, 2010 at 1:50 PM, ZagZig <po...@web.de> wrote:
> cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
>
> which is correct, but i would like to print out the name of the element with
> the invalid value.

> line number: 33
> column number: 22

you are using SAXParseException [1] class to retrieve error details
(which we should). This also inherits methods from SAXException [2].

So we are limited to error information provided by these classes.

As far as your ability to point to the relevant places in XML or
schema documents, I think line and column numbers should be
sufficient.

[1] http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/SAXParseException.html
[2] http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/SAXException.html



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: missing element name in validation result

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
There is more than one error message generated by the schema validator,
however you are only getting the first one because your ErrorHandler
terminates processing immediately by throwing an exception.

If you do not throw this exception your ErrorHandler will be called again
with another SAXParseException containing an error message like:

cvc-type.3.1.3: The value '' of element 'ID' is not valid.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

ZagZig <po...@web.de> wrote on 08/20/2010 04:20:44 AM:

> Hello everyone,
>
> i've a problem with the result of the validation. I validate my xml file
> against a xsd and everything is working fine, except that i can't get the
> name of the element that was not correctly filled. That means if i've an
> empty element "id" in my xml, which is from type integer, the error
message
> i got is
>
> cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
>
> which is correct, but i would like to print out the name of the element
with
> the invalid value.
>
> All information my errorhandler gives me are
>
> publicId: null
> systemId: null
> line number: 33
> column number: 22
> localized message: cvc-datatype-valid.1.2.1: '' is not a valid value for
> 'integer'.
> message: cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
> toString(): org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: ''
is
> not a valid value for 'integer'.
>
> <code>
> public class MyErrorHandler implements ErrorHandler {
>
>    public void error(SAXParseException arg0) throws SAXException {
>       System.out.println("publicId: " + arg0.getPublicId());
>       System.out.println("systemId: " + arg0.getSystemId());
>       System.out.println("line number: " + arg0.getLineNumber());
>       System.out.println("column number: " + arg0.getColumnNumber());
>       System.out.println("localized message: " + arg0.getLocalizedMessage
());
>       System.out.println("message: " + arg0.getMessage());
>       System.out.println("toString(): " + arg0.toString());
>       System.out.print("Parsing XML failed due to a:\n" +
> arg0.getClass().getName());
>       throw arg0;
>
>    }
>
>    public void fatalError(SAXParseException arg0) throws SAXException {
>       System.out.println("publicId: " + arg0.getPublicId());
>       System.out.println("systemId: " + arg0.getSystemId());
>       System.out.println("line number: " + arg0.getLineNumber());
>       System.out.println("column number: " + arg0.getColumnNumber());
>       System.out.println("localized message: " + arg0.getLocalizedMessage
());
>       System.out.println("message: " + arg0.getMessage());
>       throw arg0;
>
>    }
>
>    public void warning(SAXParseException arg0) throws SAXException {
>       System.out.println("publicId: " + arg0.getPublicId());
>       System.out.println("systemId: " + arg0.getSystemId());
>       System.out.println("line number: " + arg0.getLineNumber());
>       System.out.println("column number: " + arg0.getColumnNumber());
>       System.out.println("localized message: " + arg0.getLocalizedMessage
());
>       System.out.println("message: " + arg0.getMessage());
>       throw arg0;
>
>    }
>
> }
> </code>
>
> The element definition in the xsd is
>
>     <xs:element name="ID" type="ID" />
>
>     <xs:simpleType name="ID">
>         <xs:restriction base="xs:integer">
>             <xs:totalDigits value="7" />
>         </xs:restriction>
>     </xs:simpleType>
>
> Has somebody an idea how i can solve my problem?
>
> Thanking you in advance for any help you can give me.
>
> --
> View this message in context: http://old.nabble.com/missing-element-
> name-in-validation-result-tp29489740p29489740.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org