Paul, thank you for finding this. I appreciate the quick response. I had spent
a while trying to search through the javadocs and google for the concept of a
SchemaDocument but with no luck. With the research I had done before, I have
been able to add to the code to remove the implementation dependence you
mention. Here are the changes for the benefit of everyone else. Maybe this can
find its way into the FAQ.
Add the additional imports:
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaTypeLoader;
Modified method for an instance document:
private void go() throws Exception {
File xmlFile = new File("Fubar.xml");
FubarDocument doc = FubarDocument.Factory.parse(xmlFile);
if (!doc.validate()) {
System.out.println("Document validation failed");
} else {
System.out.println("Document is valid");
// get the schematype and the type loader
SchemaType st = doc.schemaType();
SchemaTypeLoader stl = st.getTypeSystem();
// get the name of the schema source file
String source = st.getSourceName();
System.out.println("schema source doc:" + source);
// parse it
java.io.InputStream is = stl.getSourceAsStream(source);
SchemaDocument schemadoc = SchemaDocument.Factory.parse(is);
// get the version information
System.out.println("tns: " +
schemadoc.getSchema().getTargetNamespace());
System.out.println("version: " +
schemadoc.getSchema().getVersion());
}
}
You can also get the version from a newly created instance document that is not
fully populated by changing factory method to newInstance() and eliminating the
doc.validate().
FubarDocument doc = FubarDocument.Factory.newInstance();
In case anyone is wondering why do any of this? I added a required schema
version attribute to my xsd and want to validate the instance document to the
schema version. In addition, when creating a new instance, I can populate the
required schema version attribute.
______________________________________________________________________
CONFIDENTIALITY NOTICE: This email from the State of California is for the sole
use of the intended recipient and may contain confidential and privileged
information. Any unauthorized review or use, including disclosure or
distribution, is prohibited. If you are not the intended recipient, please
contact the sender and destroy all copies of this email.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]