On Fri, 21 Mar 2003 08:00:38 -0800, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM> wrote:
>> I've followed a couple of threads relating to validation messages.
>> Basically the validation messages only say "length was 2 but maximum
>> length is 1". It doesn't tell me what element it was, nor what the data
>> was. So Is there a plan to give at least the element name and the data
>> value in the future?
>
>Oh, but those threads are about "on-demand" validation --- a kind of
>validation you do on JAXB contents, not when you are unmarshalling.
Right. Actually I am doing on-demand.
>When you are unmarshalling from XML, then you can access the location
>information and it gives you the line number, file name, and etc. I
>believe that's equivalent of what Xerces produces. Obtain
>ValidationEventLocator from ValidationEvent and check out its properties.
I decided not to use unmarshall-time validation because the supplier of the data doesn't know anything about XML. Actually I have to convert his data to XML on the fly before unmarshalling. This will change in the future, but for now the most useful info I could give him would be to tell him which data values are invalid and why.
>Unfortunately the default ValidationEventHandler doesn't print the line
>number, so that might be why you think we don't provide that information,
>but in the next release the line number will be printed by default.
>
>
>> Is this error coming because what I'm doing is not possible, or because
>> I'm doing something wrong?
>
>Hard to tell, but I suspect the latter. After all, when you pass in File,
>Reader, InputStream or things like that, we internally use the
>UnmarshallerHandler to unmarshal it. So it's kind of strange that it
>doesn't work.
>
>Have you turned on the namespace support on the parser (aka
>setNamespaceAware(true))?
Actually I'm using noNamespaceSchemaLocation. That still works for me when I do a straight SAX parse. Could it be causing a problem now? The schema from which I generated my JAXB classes does not have a namespace.
>Could you post the relevant part of the source code?
JAXBContext jc = JAXBContext.newInstance("gov.customs.msb.capes.servlet.selcteUpload");
Unmarshaller u = jc.createUnmarshaller();
UnmarshallerHandler unmarshallerHandler = u.getUnmarshallerHandler();
u.setValidating(false);
XMLReader parser = new org.apache.xerces.parsers.SAXParser();
parser.setProperty("
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"
http://localhost:8080/capes/fileUpload/MassInsertSchema.xsd");
parser.setFeature( "
http://xml.org/sax/features/validation", true);
parser.setFeature( "
http://xml.org/sax/features/namespaces", false);
parser.setFeature( "
http://apache.org/xml/features/validation/schema", true);
parser.setFeature("
http://apache.org/xml/features/validation/dynamic",false);
DefaultHandler handler = new MassInsertSAXHandler();
parser.setContentHandler(unmarshallerHandler);
parser.setErrorHandler(handler);
InputSource input = new InputSource(is);
parser.parse(input);
>
>regards,
>--
>Kohsuke KAWAGUCHI 408-276-7063 (x17063)
>Sun Microsystems kohsuke.kawaguchi_at_sun.com