Hi folks,
First, thanks for the tip earlier about atomic type
validation, Cezar. Here is another issue I've been working
on, that I hope someone has insight into. It is similar to
this old thread:
http
://mail-archives.apache.org/mod_mbox/xmlbeans-user/200501.mb
ox/%3c4B2B4C417991364996F035E1EE39E2E124FC35 uskiex01.amer.bea.com%3e
I have a SchemaType object that I've loaded from an .xsd
file. I also have a piece of data that I'd like to validate
against that SchemaType object. Here is how I'm trying to
do it:
String value = "car"; // The value I want to
validate.
XmlObject xmlObject =
XmlObject.Factory.parse("<product>" + value
+ "</product>"); // I make a temporary
XmlObject to hold the value.
xmlObject = xmlObject.selectChildren(new
QName("product"))[0]; // I get the <product>
element (what I want to validate), not the doc root.
xmlObject = xmlObject.changeType(schemaType); // I specify
the type to validate against.
return xmlObject.validate(); // I perform validation. This
always returns false...
And here is the schema snippet that defines the type that is
held in schemaType:
<xsd:simpleType name="productType">
<xsd:restriction base='xsd:string'>
<xsd:enumeration value='truck'/>
<xsd:enumeration value='car'/>
</xsd:restriction>
</xsd:simpleType>
I get an error (not an exception) when xmlObject.validate()
is called; I used XmlOptions.setErrorListener() to get the
error info. Here is the error:
Message: Invalid type
Location of invalid XML: <product>car</product>
Does the mailer thread I linked earlier mean that I can't
validate programatically this way? The types I'm dealing
with are completely unknown before runtime, as these are
end-user-specified schemas and values. Compiling these into
Java classes isn't an option for this application.
If the way I'm doing it is wrong, is there another way?
Thanks for the help,
Vance
------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribe xmlbeans.apache.org
For additional commands, e-mail: user-help xmlbeans.apache.org
|