InferHandler extends DefaultHandler { public Schema getSchema() { for (Map.Entry<Name, ElementDeclInferrer> entry : inferrerMap.entrySet()) { ElementDecl decl = (entry.getValue()).infer(); Name name = entry.getKey(); schema.getElementDecls().put(name, decl); } schema.setStart(makeStart()); schema.getPrefixMap().keySet().retainAll(usedNamespaceUris); return schema; } InferHandler(DatatypeLibraryFactory factory); void startElement(String uri, String localName,
                           String qName, Attributes attributes); void startPrefixMapping(String prefix, String uri); void characters(char ch[], int start, int length); void endElement(String uri, String localName, String qName); Schema getSchema();  }
@Test(dataProvider = "samples") public void testTypeInferenceForAttribute(String xmlSource, String type) throws SAXException, IOException { InferHandler handler = new InferHandler(new DatatypeLibraryFactoryImpl(new RegexEngineImpl())); SAXResolver resolver = new SAXResolver(); XMLReader xr = resolver.createXMLReader(); xr.setContentHandler(handler); xr.parse(new InputSource(new StringReader(xmlSource))); Schema schema = handler.getSchema(); for (Map.Entry<Name, ElementDecl> entry : schema.getElementDecls() .entrySet()) { Name name = entry.getKey(); ElementDecl elementDecl = entry.getValue(); if ("element".equals(name.getLocalName())) { for (Map.Entry<Name, AttributeDecl> attEntry : elementDecl.getAttributeDecls().entrySet()) { AttributeDecl att = attEntry.getValue(); Name attName = attEntry.getKey(); if ("att".equals(attName.getLocalName())) { Name typeName = att.getDatatype(); Assert.assertEquals(typeName.getLocalName(), type); } } } } }