Java tutorial
//package com.java2s; /* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ import java.io.InputStream; import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import org.xml.sax.SAXException; public class Main { private static final SchemaFactory SCHEMA_FACTORY = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); public static Schema loadSchema(final InputStream... fromStreams) { Source[] sources = new Source[fromStreams.length]; int i = 0; for (InputStream stream : fromStreams) { sources[i++] = new StreamSource(stream); } try { return SCHEMA_FACTORY.newSchema(sources); } catch (SAXException e) { throw new IllegalStateException("Failed to instantiate XML schema", e); } } }