MaryDomUtils extends DomUtils { public static boolean isSchemaValid(Document doc) throws MaryConfigurationException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MaryNormalisedWriter mnw = new MaryNormalisedWriter(); try { mnw.output(doc, baos); } catch (TransformerException te) { throw new MaryConfigurationException("Cannot serialize document for Schema-valid parsing", te); } try { parseDocument(new ByteArrayInputStream(baos.toByteArray()), true ); } catch (ParserConfigurationException pce) { throw new MaryConfigurationException("Problem setting up parser", pce); } catch (IOException ioe) { throw new MaryConfigurationException("IOException should not occur but it does", ioe); } catch (SAXException se) { return false; } return true; }  static Element encloseWithMTU(Element t, String orig, String accentPosition); static Element appendToken(Element t, String newTokenText); static String tokenText(Element t); static void setTokenText(Element t, String s); static Element createBoundary(Document doc); static Locale getLocale(Document doc); static boolean isSchemaValid(Document doc); static void printDocument(Document doc, OutputStream out);  }
@Test public void canValidateMaryXML() throws MaryConfigurationException { Document doc = createValidMaryXML(); assertTrue(MaryDomUtils.isSchemaValid(doc)); }
@Test public void canDetectInvalidMaryXML() throws MaryConfigurationException { Document doc = createInvalidMaryXML(); assertFalse(MaryDomUtils.isSchemaValid(doc)); }