title: Java, Validate XML against an embedded schema in WSDL
body: <p>I have a <code>.wsdl</code> file with an embedded schema. I want to validate an XML file/string using that <code>.wsdl</code> file (the same way you would validate against an <code>.xsd</code>). The schema is between the <code>&lt;types&gt;</code> tag. I have this so far:</p>
  
  <pre><code>public boolean validate(String xmlString) {
      try {
          // Convert to input stream
          InputStream xml = new ByteArrayInputStream(xmlString.getBytes());
  
          SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          Schema schema = schemaFactory.newSchema(new File("wsdl_filepath"));
  
          // Validate against wsdl
          Validator validator = schema.newValidator();
          validator.validate(new StreamSource (xml));
  
          // XML Message is valid
          return true;
  
      } catch (SAXException e) {
          e.printStackTrace();
          return false;
  
      } catch (IOException e) {
          e.printStackTrace();
          return false;
      }
  }
  </code></pre>
  
  <p>This doesn't work, however. This validator works if validating against an <code>.xsd</code>. I'm not sure how to modify it to validate against the embedded schema.</p>
  
  <p>Any help would be appreciated, thank you!</p>