private static VersionDefinitionXml load(InputStream stream) throws Exception {

    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    XMLStreamReader xmlReader = xmlFactory.createXMLStreamReader(stream);

    xmlReader.nextTag();
    String xsdName = xmlReader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "noNamespaceSchemaLocation");

    if (null == xsdName) {
      throw new IllegalArgumentException("Provided XML does not have a Schema defined using 'noNamespaceSchemaLocation'");
    }

    InputStream xsdStream = VersionDefinitionXml.class.getClassLoader().getResourceAsStream(xsdName);

    if (null == xsdStream) {
      throw new Exception(String.format("Could not load XSD identified by '%s'", xsdName));
    }

    JAXBContext ctx = JAXBContext.newInstance(VersionDefinitionXml.class);
    Unmarshaller unmarshaller = ctx.createUnmarshaller();

    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema(new StreamSource(xsdStream));
    unmarshaller.setSchema(schema);

    try {
      VersionDefinitionXml xml = (VersionDefinitionXml) unmarshaller.unmarshal(xmlReader);
      xml.xsdLocation = xsdName;
      return xml;
    } finally {
      IOUtils.closeQuietly(xsdStream);
    }
  }
Parses a stream into an object graph
@param stream  the stream
@return the definition
@throws Exception
ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java