/** * Prints an XML schema in a String. * * @param schema the XML schema * @return the content as a string * @throws TransformerException if formatting of output fails */ protected String toString(final XmlSchema schema) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); try { tFactory.setAttribute("indent-number", "4"); } catch (IllegalArgumentException e) { _log.warn("Unable to set indent-number on transfomer factory", e); } StringWriter writer = new StringWriter(); Source source = new DOMSource(schema.getAllSchemas()[0]); Result result = new StreamResult(writer); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.STANDALONE, "no"); transformer.transform(source, result); writer.flush(); return writer.toString(); }
/** * Customize the XML schema by applying an XSLT stylesheet. * * @param schema the XML schema * @param xsltFileName the XSLT stylesheet * @return the transformed XML schema as a string * @throws TransformerException if XSLT transform fails */ protected XmlSchema customize(final XmlSchema schema, final String xsltFileName) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); StringWriter writer = new StringWriter(); Source source = new DOMSource(schema.getAllSchemas()[0]); Result result = new StreamResult(writer); Source xsltSource = new StreamSource(new File(xsltFileName)); Transformer transformer = tFactory.newTransformer(xsltSource); transformer.transform(source, result); writer.flush(); StringReader reader = new StringReader(writer.toString()); XmlSchemaCollection schemaCol = new XmlSchemaCollection(); return schemaCol.read(reader, null); }
/** * Merge includes and imports (with identical target namespace) into the XML * Schema and then remove the included/imported items. * <p/> * * @return a new XmlSchema where all includes and imports are expanded */ public static XmlSchema pullIncludes(final XmlSchema xmlSchema) { Document[] docs = xmlSchema.getAllSchemas(); if (docs.length < 2) { return xmlSchema; } XmlSchemaCollection schemaCol = new XmlSchemaCollection(); Document merged = mergeIncludes(docs, xmlSchema.getTargetNamespace()); XmlSchema mergedSchema = schemaCol.read(merged, null); return mergedSchema; }
XmlSchema schemaDef = xsDef.getSchema(); schemaDef.setNamespaceContext(prefixMap); Document[] docs = schemaDef.getAllSchemas(); document = docs[docs.length-1]; document.setDocumentURI(xsDef.getLocation().toString());
XmlSchema schemaDef = xsDef.getSchema(); schemaDef.setNamespaceContext(prefixMap); Document[] docs = schemaDef.getAllSchemas(); document = docs[docs.length-1]; document.setDocumentURI(xsDef.getLocation().toString());
nsMap.add("tns", schema.getTargetNamespace()); org.w3c.dom.Element el = schema.getAllSchemas()[0].getDocumentElement(); wsdlSchema.setElement(el);