Menu

schema

redmitry

Working with XML Schema

tinyWSDL does not parse XML Schemas so working with XML Schema is similar to working with unknown extensions.

Types types = description.getTypes();
List<Element> elements = types.getExtensionElements(SchemaTypesExtensions.XML_SCHEMA_ELEM);


Note that even SchemaTypesExtensions is defined there is no implementation provided,
so the code below returns an empty list.

SchemaTypesExtensions extensions = (SchemaTypesExtensions)types.getComponentExtensions(WSDLPredefinedExtension.SCHEMA.URI);
List<? extends Schema> schemas = extensions.getSchemas();


This is done to do not depend on any particular XML Schema parser.

tinyXMLSchema is an XML Schema extension based on Apache XML Schema 2 library and provided as an extension package.
When tinyXMLSchema is present, the code above works and it is possible to get Apache XmlSchema object:

SchemaTypesExtensions extensions = (SchemaTypesExtensions)types.getComponentExtensions(WSDLPredefinedExtension.SCHEMA.URI);
for (Schema schema : extensions.getSchemas()) {
  XmlSchema xmlSchema = schema.getSchema();
}


Inserting a new XML Schema:

SchemaTypesExtensions extensions = (SchemaTypesExtensions)types.getComponentExtensions(WSDLPredefinedExtension.SCHEMA.URI);
Schema schema = extensions.newSchema();
XmlSchema xmlSchema = (XmlSchema)schema.getSchema();
xmlSchema.setTargetNamespace("http://example.com");
extensions.addSchema(schema);


Also ElementDeclaration object (for example obtained from InterfaceFault) will return XmlSchemaElement as its content:

ElementDeclaration elementDeclaration = interfaceFault.getElementDeclaration();
XmlSchemaElement xmlSchemaElement = elementDeclaration.getContent();

Obviously when tinyXmlSchema extension is used Apache Xml Schema 2.0 core library must be also present.


Related

Wiki: Home
Wiki: extensions
Wiki: wsdl11

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.