If you have additional questions that you would like to see answered in future versions of this FAQ or in the Javadoc, please e-mail them to rschloss@us.ibm.com.
1. Can this library be used within Eclipse-based tools, and outside of
the Eclipse environment?
GO
2. Is there a way to have schema documents which
reference other schema documents through <include> <import> or <redefine>
be fetched from locations other than those given in the schemaLocation attribute?
GO
3. What version of W3C XML Schema is accepted as input?
GO
4. Are there sample Java methods that show how to use the API?
GO
5. Where do I download the latest code?
GO
6. Does this library allow me to supply an instance document and have it
validated
against the schema?
GO
7. What should my Java CLASSPATH include, in order to use the library?
GO
8. What version(s) of Eclipse does this code work on?
GO
9. What version(s) of WebSphere Studio Workbench does this code work on?
GO
10. What version(s) of WebSphere Studio Application Developer does this code work on?
GO
11. When modification are made to a schema document which was used by another schema document
(which has been loaded by this library),
will my code need to explicitly make the corresponding modifications to the using schema document?
GO
12. What steps should I take to install the source code in one WSAD 4.0 project,
and to identify another project with my own code as dependent upon and using this library?
GO
13. When I report a bug, where do I find the exact version number of the library?
GO
14. To obtain a component of a schema by name, or find out such a component does
not exist in the schema, what sequence of code should be used?
GO
15. What facilities of the schema language are not currently supported?
GO
16. How can the attribute maxOccurs="unbounded" be set on a particle?
GO
17. Why does this library use the EMF runtime under the covers?
GO
18. How do I start to learn how to use this? Are any examples available?
GO
19. When passed an object of type XSDSchema, what method tells me if it was parsed from a Resource?
GO
20. When passed an object of type XSDSchema, what method permits me to alter the Resource in which it will be serialized?
GO
21. Where are the JAR files I need on my classpath?
GO
22. How do I remove a component from the Schema completely -- not leaving any
dangling references?
GO
23. How does the model choose what prefix to use in QNAMEs for a namespace URI in serializing the schema,
when more than one prefix has been associated with that namespace?
GO
24. Does the o1.equals(o2) method
determine "semantic equivalence" between two schema components?
GO
25. What happens if I pass a DOM which claims to be the XML representation of a Schema, but
there are errors in the attribute values?
GO
26. If I want the library to parse a Schema from a file which does not have the extension .xsd,
or serialize a Schema to a file which does not have the extension .xsd,
what do I do?
GO
27. Is there a function to inquire "Is this parsed or constructed schema completely correct?"
GO
28. Is there a function to inquire "Did this parsed schema
have unresolved <include> <import> or <redefine> directives?"
GO
29. What happens if I add a schema component to schema2 that I had previously added to schema1?
GO
30. Is there a way to determine if a string represents a value that a particular simpleType would
consider valid?
GO
31. What version of the Java Runtime Environment is this
library tested on?
GO
32. ComplexTypes and SimpleTypes only have at most 1 annotation. Why is there XSDTypeDefinition.getAnnotations() in addition to getAnnotation().
What is getAnnotations() used for?
GO
33. What mailing list should be used to discuss the use of this feature?
GO
Yes, it can be used within Eclipse and outside of Eclipse.
Please note that when running outside Eclipse,
you need to set a system property named VABASE, for example:
java -DVABASE=directoryWhichContainsASubdirectoryNamedPlugins ....
com.ibm.etools.emf.Init.init(); com.ibm.etools.emf.resource.UriMappingRegister.registerMapping( "textThatWouldAppearInSchemaLocation", "fileNameToUseInstead.xsd"); com.ibm.etools.emf.resource.UriMappingRegister.registerMapping( "text2ThatWouldAppearInSchemaLocation", "fileName2ToUseInstead.xsd"); com.ibm.etools.emf.resource.ContextResourceFactoryRegister crfr = new com.ibm.etools.emf.resource.ContextResourceFactoryRegister(); com.ibm.etools.emf.resource.Context context = crfr.getContextFactory().makeContext(); com.ibm.etools.emf.resource.ResourceSet set = crfr.getResourceSetFactory().makeResourceSet(); com.ibm.etools.emf.resource.URIConverter converter = com.ibm.etools.emf.resource.URIConverterRegister.getURIConverter(); context.setURIConverter(converter); set.setContext(context);
Sample code that includes links back to the javadoc is at: XSDPrototypicalSchema.html.
Examples of convenience functions also illustrate the use of the bare API. Those example convenience functions are in the source code. Info about them is located at XSDSchemaBuildingTools.html and XSDSchemaQueryTools.html.
You should not replace com.ibm.etools.emf or com.ibm.etools.xsd in the plugins directory of WSAD 4.0.3 . You may import this code into a project you create in your WSAD workspace.
To identify another project with your own code as dependent upon and using this library, follow these steps :
The resolveXXXDeclaration and resolveXXXDefinition methods declared in Interface com.ibm.etools.xsd.XSDConcreteComponent allow lookup of components that have names. Note that these methods always return something. If your schema does not have the component you are looking for, the returned value will be a newly manufactured reference to it.
Here is an example method to return the component or return null if it was not in the schema, in this case for an Attribute Declaration with a particular name:
/** return the XSDAttributeDeclaration of a given namespace and name defined in a given schema or a schema it includes, redefines or imports */
static XSDAttributeDeclaration
getAttributeDeclaration(XSDSchema schema, String namespace, String name) {
XSDAttributeDeclaration ret=schema.resolveAttributeDeclaration(namespace,name);
if (ret.isAttributeDeclarationReference()) {
return null;
} else {
return ret;
}
}
| plugins/org.eclipse.core.boot_2.0.0/boot.jar |
| plugins/org.eclipse.core.runtime_2.0.0/runtime.jar |
| plugins/org.apache.xerces_4.0.3/xercesImpl.jar |
| plugins/org.apache.xerces_4.0.3/xmlParserAPIs.jar |
| plugins/org.eclipse.core.resources_2.0.0/resources.jar |
For element declarations, attribute declarations, named model groups definitions, and attribute group definitions, you would do something like this:
XSDElementDeclaration xsdElementDeclaration =
yourSchema.resolveElementDeclaration("elementName");
XSDSchema xsdSchema = xsdElementDeclaration.getSchema();
if (xsdSchema != null)
{
xsdSchema.getContents().remove(xsdElementDeclaration)
}
So you get the resolved component, make sure it's in a schema to ensure that it's not an unresolved component, and then you remove it from the schema contents.
For type definitions, this approach is appropriate:
XSDTypeDefinition xsdTypeDefinition =
yourSchema.resolveTypeDefinition("typeName");
XSDConcreteComponent container = xsdTypeDefinition.getContainer();
if (container instanceof XSDSchema)
{
((XSDSchema)container).getContents().remove(xsdTypeDefinition)
}
else if (container instanceof XSDRedefine)
{
((XSDRedefine)container).getContents().remove(xsdTypeDefinition)
}
So you get the resolved component, get its container, figure out what type of container it is, and then you remove it from the appropriate relation of that container. Note that type definitions can be contained by redefines as well as directly by the schema.
com.ibm.etools.emf.resource.ResourceFactoryRegister.registerExtension("foo",
new XSDResourceFactoryImpl());
if (xsdSchema.getAllDiagnostics().isEmpty()) { xsdSchema.validate(); }
if (xsdSchema.getAllDiagnostics().isEmpty()) { /* No Unresolved directives */ }
else { */ Unresolved directives or other problems */ }
yourSimpleTypeDefinition.isValidLiteral("a-particular-string")
will give you the boolean answer.