Java XML String Transform getValidator(String path)

Here you can find the source of getValidator(String path)

Description

get Validator

License

Open Source License

Declaration

private static Validator getValidator(String path) throws SAXException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.XMLConstants;

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;

public class Main {
    private static Validator getValidator(String path) throws SAXException, IOException {
        String xsdUri = XMLConstants.W3C_XML_SCHEMA_NS_URI;
        SchemaFactory sf = SchemaFactory.newInstance(xsdUri);
        InputStream stream = new FileInputStream(path);
        StreamSource xsd = new StreamSource(stream);
        Schema schema = sf.newSchema(xsd);
        return schema.newValidator();
    }/*from   w w  w . j a  v  a 2  s .  co  m*/
}

Related

  1. getSourceAsString(Source source)
  2. getStreamResultForFile(String filename)
  3. getString(Node node, boolean indent)
  4. getStringFromStreamSource(StreamSource src)
  5. getTemplates(String name)
  6. getXmlStringFromSource(Source payload)
  7. identity(String xml)
  8. indentXML(String fileContent)
  9. loadSourceFromURL(String systemID)