Hi Jacob,
Thanks for the tip. I took a look at InstanceValidator, and noticed that the
key difference was that it uses the same SchemaTypeLoader instance it used to
load the SchemaTypes to also load the XML to be validated. I tried that, no
dice. However, I did a little more debugging:
* The error value I get back when validation fails is: cvc-elt.1
* XmlErrorCodes describes this error as "ELEM_LOCALLY_VALID$NO_TYPE",
"cvc-elt.1: See clause 1 of XMLSchema Structures 1.0: Element Locally Valid
(Element)"
* I took a look at the suggested part of the schema spec, and that clause reads
"1 The declaration must not be absent."
* I took a look at all the XmlBeans code that includes the words "invalid
type", and found that the most likely source of this is this part of
QNameHelper:
if (sType.isNoType() || sType.getOuterType() == null)
{
return "invalid type";
}
* Using a debugger, I was able to confirm that the SchemaType I'm validating
against DOES return null for getOuterType() (not sure what this signifies --
the Javadocs for this method are very terse).
So long story short, let me restate my goal, and hopefully someone has another
lifejacket they can throw me as I float around in this sea of schemas and XML:
- I have a value, as a string. Such as "car".
- I have a SchemaType object (a simple type), that was loaded from a schema
file, that says that valid values are "car" or "truck".
- I want to validate that "car" is a valid value, given the SchemaType object.
- I create an XmlObject like this:
XmlObject xmlObject = schemaTypeLoader.parse("<whatever>" + value +
"</whatever>", null, null); // Note that the SchemaType specified here is null,
I don't have or want a type that defines "whatever"
- I select the "whatever" child, because I am not actually interested in the
tag, just the (simple) value.
xmlObject = xmlObject.selectChildren(new QName("whatever"))[0];
- I change the type of the object to the type I'm interested in validating
against:
xmlObject = xmlObject.changeType(schemaType);
However, xmlObject.validate() always returns false, and if I use an error
listener I find out the information I described earlier in this email.
I've spent quite a few hours looking into this, and would sincerely appreciate
any advice others may have as to how I can perform this validation. Note that
the schemas involved have not been compiled into Java objects, as this is a
fully dynamic application, where the schemas are loaded -- the user types in a
value -- and then the SchemaType objects are referenced to check its validity.
Thanks so much!
- Vance
> -------- Original Message --------
> Subject: Re: Validating a value against a SchemaType object
> From: "Jacob Danner" <[EMAIL PROTECTED]>
> Date: Wed, May 02, 2007 6:03 pm
> To: [email protected]
>
> Hi Vance,
> There are some scripts that you can use to validate an instance to a
> schema type. Take a peek at the svalidate/validate scripts in the bin
> directory.
> The class that is called is:
> org.apache.xmlbeans.impl.tool.InstanceValidator
> and might do what you are looking for.
> Hope this helps,
> -Jacob Danner
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]