public String toXml() throws Exception {

    JAXBContext ctx = JAXBContext.newInstance(VersionDefinitionXml.class);
    Marshaller marshaller = ctx.createMarshaller();
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

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

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

    try {
      Schema schema = factory.newSchema(new StreamSource(xsdStream));
      marshaller.setSchema(schema);
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.setProperty("jaxb.noNamespaceSchemaLocation", xsdLocation);

      StringWriter w = new StringWriter();
      marshaller.marshal(this, w);

      return w.toString();
    } finally {
      IOUtils.closeQuietly(xsdStream);
    }
  }
Returns the XML representation of this instance.
ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java