POLITECHNIKA RZESZ' - Wydział Elektrotechniki i Informatyki
DocumentBuilderFactory dbfactory =
DocumentBuilderFactory.newlnstance(); dbfactory.setNamespaceAware(true); // konieczne !!! I Parsowanie
DocumentBuilder builder = dbfactory.newDocumentBuilder(); -
Document document = builder.parse(new File("myXm1File.xm1")); SchemaFactory factory =
SchemaFactory-newlnstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source scheraaFile = new StreamSource(new File("mySchemaFile.xsd")); Schema schema = factory-newSchema(schemaFile) ;
Validator validator = schema.newValidator();
try { [ Walidacja j
validator.validate(new DOMSource(document));
System.out.println("Document is valid !");
Element root = document. getDocumentElement (f~; j przetwarzanie^
System.out.println("root Element Name: " + root.getTagName());
} catch (SAXException ex) (
System.out.println("Document is not valid:\n"+ ex.getMessage());
}