Hi all,
I wanted to share the solution to my earlier question about how to validate a
single String value against a given SchemaType instance (in isolation, not part
of a complete document). Thanks to advice from both Jacob Danner and Cezar,
this is how to do it:
ValidatorUtil.validateSimpleType(schemaType, value, collection, null);
This of course only works for simple SchemaTypes, but this meets 80%+ of the
needs of our project, so I'm very grateful.
Thanks for the help,
Vance
> >
> > I just dropped this into my project, and it's validating those
> atomic types like a charm. This should meet the needs of our
> project for this iteration, I can always come back to this if we
> need stricter validation in the future.
> >
> > Thanks so much for the help,
> > Vance
> >
> > > -------- Original Message --------
> > > Subject: Re: Validating a value against a SchemaType object
> > > From: "Jacob Danner" <[EMAIL PROTECTED]>
> > > Date: Tue, May 08, 2007 3:24 pm
> > > To: "Vance Vagell" <[EMAIL PROTECTED]>
> > >
> > > for #2, did Cezar's advice not work?
> > > validateAtomicType(ScemaType, String, Event) ?
> > > -Jacobd
> > >
> > > On 5/8/07, Vance Vagell <[EMAIL PROTECTED]> wrote:
> > > > Hi Jacob,
> > > >
> > > > Thanks for taking the time to help out. Unfortunately, the XSD is
> > > user-provided, meaning that it is a full-fledged schema that we have
> > > no control over. We display fields that match what the schema
> > > requires (and we have this part working great using XmlBeans), but
> > > as we've been discussing, we're having issues validating individual
> > > user-entered values.
> > > >
> > > > You noted two approaches in your response:
> > > >
> > > > 1) Create a mock XML element (I assume
> VehicleTypeValidateElement is
> > > basically an XmlObject in your example) out of some XML created
> > > on-the-fly that includes the value to be validated.
> > > >
> > > > * I've tried this, first creating an XmlObject and then using
> > > xmlObject.changeType(SchemaType) before calling validate(), but I
> > > always get a "Invalid Type" error. My May 3rd post to this mailer
> > > has a lot of detail around my investigations into this, but I
> > > basically ran into a roadblock and couldn't resolve the "Invalid
> > > Type" error.
> > > >
> > > > 2) Use XmlBeans classes like XmlInt to validate atomic types.
> > > >
> > > > If this is possible, it could be a great workaround until we can
> (if
> > > ever) get #1 to work. However, I just took a look at the Javadocs
> > > for XmlInt and I don't see how we can use this. Here are the
> > > problems:
> > > >
> > > > - How can we go from the SchemaType object (which we parsed from
> the
> > > arbitrary user-provided XSD), to one of these objects (XmlInt,
> > > XmlString, etc.)?
> > > >
> > > > - Once we have an XmlInt, for example, how can we use that for
> > > validation? It seems that each of these classes has its own "set"
> > > method with a unique name; XmlInt has setIntValue() for example.
> > > The generic set() is deprecated, so even if we knew which of these
> > > classes to use, I'm not sure how we'd know which set-method to use.
> > > >
> > > > If you could enlighten me on how to validate a value against an
> > > atomic type, given the SchemaType we have, that would be a great
> > > step in the right direction. We could always come back and look at
> > > constraints in future releases of our project.
> > > >
> > > > Thanks so much,
> > > > Vance
> > > >
> > > > -----------------------------------------------
> > > > Have you tried using simpleTypes in your XSD for these values.
> > > > ie
> > > > <xs:simpleType name="vehType">
> > > > <xs:restriction base="xs:token"> <!-- like a string but
> stricter -->
> > > > <xs:enumeration value="car"/>
> > > > <xs:enumeration value="truck"/>
> > > > </xs:restriction>
> > > > </xs:simpleType>
> > > >
> > > > You could then refer to this type in various places in the schema
> > > <xs:complexType name="vehicle">
> > > > <xs:sequence>
> > > > <xs:element name="typeOfVehicle" type="tns:vehType"/>
> > > > ...
> > > > <xs:element name="VehicleTypeValidateElement" type="tns:vehType"/>
> > > And when you got the user input you would be able to do something
> > > like:
> > > > VehicleTypeValidateElement v =
> > > > VehicleTypeValidateElement.Factory.parse("<VehicleTypeValidateElement>"+userInput+"</VehicleTypeValidateElement>");
> > > > and then ...
> > > > v.validate()
> > > > or what not.
> > > >
> > > > There are several ways to represent the types you could use for
> > > validation in your xsd. I find myself going back to:
> > > > http://www.xfront.com/GlobalVersusLocal.html when the types I want
> > > are not POJOs as I want to access them.
> > > >
> > > > As far as simple atomic types, are you having problems using
> > > XmlInt.setValue, etc?
> > > >
> > > > Thanks,
> > > > -Jacob Danner
> > > >
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]