List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI
String W3C_XML_SCHEMA_NS_URI
To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.
Click Source Link
From source file:fr.cls.atoll.motu.library.misc.xml.XMLUtils.java
/** * Validate xml./*from ww w . j ava 2s .c om*/ * * @param inSchema the in schema * @param inXml the in xml * * @return the xML error handler * * @throws MotuException the motu exception */ public static XMLErrorHandler validateXML(InputStream inSchema, InputStream inXml) throws MotuException { return XMLUtils.validateXML(inSchema, inXml, XMLConstants.W3C_XML_SCHEMA_NS_URI); }
From source file:arxiv.xml.XMLParser.java
/** * Constructs a new XML parser by initializing the JAXB unmarshaller and setting up the XML validation. * * @throws HarvesterError if there are any problems *//* w w w . j a v a 2 s. com*/ public XMLParser() { try { unmarshaller = JAXBContext.newInstance("org.openarchives.oai._2:org.arxiv.oai.arxivraw") .createUnmarshaller(); } catch (JAXBException e) { throw new HarvesterError("Error creating JAXB unmarshaller", e); } ClassLoader classLoader = this.getClass().getClassLoader(); List<Source> schemaSources = Lists.newArrayList(); schemaSources.add(new StreamSource(classLoader.getResourceAsStream("OAI-PMH.xsd"))); schemaSources.add(new StreamSource(classLoader.getResourceAsStream("arXivRaw.xsd"))); try { Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(schemaSources.toArray(new Source[schemaSources.size()])); unmarshaller.setSchema(schema); } catch (SAXException e) { throw new HarvesterError("Error creating validation schema", e); } }
From source file:com.amalto.core.storage.hibernate.SystemTypeMappingRepository.java
public MetadataRepository visit(ComplexTypeMetadata complexType) { MetadataVisitor<TypeMapping> creator = getTypeMappingCreator(complexType, strategy); TypeMapping typeMapping = complexType.accept(creator); // Add MDM specific record specific metadata: keep this additional fields for system objects too: MDM studio // may query these fields (see TMDM-5666). ComplexTypeMetadata database = typeMapping.getDatabase(); if (database.isInstantiable() && !database.isFrozen() && database.getSuperTypes().isEmpty()) { TypeMetadata longType = new SoftTypeRef(internalRepository, XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.LONG, false); TypeMetadata stringType = new SoftTypeRef(internalRepository, XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING, false); database.addField(new SimpleTypeFieldMetadata(database, false, false, true, Storage.METADATA_TIMESTAMP, longType, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY)); database.addField(new SimpleTypeFieldMetadata(database, false, false, false, Storage.METADATA_TASK_ID, stringType, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY)); }/*w ww . j a v a2 s. c o m*/ // Register mapping internalRepository.addTypeMetadata(typeMapping.getDatabase()); mappings.addMapping(typeMapping); return internalRepository; }
From source file:cl.vmetrix.operation.persistence.XmlValidator.java
/** * The method validatorXMLstg determinate if the String XML is correct. * @return a boolean (true or false) to indicate if the XML is correct. * @param xml is the String XML to validate against XSD Schema * @throws SAXException//www . j av a2s .c o m * @throws IOException */ public boolean validateXMLstg(String xml) throws SAXException, IOException { String rpta = ""; boolean validation = true; try { xml = new String(xml.getBytes("UTF-8")); // System.out.println("---> XML in UTF-8: "+ xml); // convert String into InputStream InputStream is = new ByteArrayInputStream(xml.getBytes()); Source xmlFile = new StreamSource(is);//new File("C:/XML/424437.xml")); // XSD schema String schemea = getFileSchema("operationSchema.xsd"); InputStream sch = new ByteArrayInputStream(schemea.getBytes()); Source schemaFile = new StreamSource(sch);//new File("main/resources/Operation.xsd")); // Preparing the schema SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(schemaFile); // Validator creation Validator validator = schema.newValidator(); // DException handle of validator final List<SAXParseException> exceptions = new LinkedList<SAXParseException>(); validator.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { exceptions.add(exception); } @Override public void fatalError(SAXParseException exception) throws SAXException { exceptions.add(exception); } @Override public void error(SAXParseException exception) throws SAXException { exceptions.add(exception); } }); // XML validation validator.validate(xmlFile); // Validation result. If there are errors, detailed the exact position in the XML and the error if (exceptions.size() == 0) { rpta = "XML IS VALID"; } else { validation = false; StringBuffer sb = new StringBuffer(); sb.append("XML IS INVALID"); sb.append("\n"); sb.append("NUMBER OF ERRORS: " + exceptions.size()); sb.append("\n"); for (int i = 0; i < exceptions.size(); i++) { i = i + 1; sb.append("Error # " + i + ":"); sb.append("\n"); i = i - 1; sb.append(" - Line: " + ((SAXParseException) exceptions.get(i)).getLineNumber()); sb.append("\n"); sb.append(" - Column: " + ((SAXParseException) exceptions.get(i)).getColumnNumber()); sb.append("\n"); sb.append(" - Error message: " + ((Throwable) exceptions.get(i)).getLocalizedMessage()); sb.append("\n"); sb.append("------------------------------"); } rpta = sb.toString(); logger.debug(rpta); } } catch (SAXException e) { logger.error("SAXException in XML validator: ", e); logger.debug(rpta); throw new SAXException(e); } catch (IOException e) { logger.error("IOException in XML validator: ", e); logger.debug(rpta); throw new IOException(e); } return validation; }
From source file:org.eclipse.winery.repository.resources.imports.xsdimports.XSDImportResource.java
@Override protected TExtensibleElements createNewElement() { TImport imp = new TImport(); imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI); return imp; }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.ProfileMarshaller.java
public ProfileMarshaller() throws JAXBException, SAXException, IOException { jaxbContext = JAXBContext.newInstance(Profile.class, TomcatDataSource.class, DbcpDataSource.class, AjpConnector.class, HttpConnector.class); Resource schemaResource = new ClassPathResource("tomcatserverconfig-profile-2.0.xsd", Profile.class); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); profileSchema = schemaFactory.newSchema(schemaResource.getURL()); }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.schema.validator.SchemaValidatorImpl.java
/** * /* w ww.ja v a2 s. co m*/ * @return <code>javax.xml.validation.Schema</code> * @throws SchemaValidationException */ private Schema getSchema() throws SAXException { URL xsdURL = getSchemaURL(); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xsdURL); return schema; }
From source file:com.geewhiz.pacify.managers.EntityManager.java
public EntityManager(File startPath) { this.startPath = startPath; try {//from w w w . jav a 2 s .c o m jaxbContext = JAXBContext.newInstance(ObjectFactory.class); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schema = factory.newSchema( new StreamSource(EntityManager.class.getClassLoader().getResourceAsStream("pacify.xsd"))); } catch (Exception e) { throw new RuntimeException("Couldn't instanciate jaxb.", e); } }
From source file:fr.cls.atoll.motu.library.misc.xml.XMLUtils.java
/** * Validate xml.//from ww w. ja v a2s . c o m * * @param inSchemas the in schemas * @param inXml the in xml * * @return the xML error handler * * @throws MotuException the motu exception */ public static XMLErrorHandler validateXML(InputStream[] inSchemas, InputStream inXml) throws MotuException { return XMLUtils.validateXML(inSchemas, inXml, XMLConstants.W3C_XML_SCHEMA_NS_URI); }