| |
33. 17. 1. 从XML架构创建XML校验器 |
|
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
public class Main {
public static void main(String[] argv) throws Exception {
String schemaLang = "http://www.w3.org/2001/XMLSchema";
SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
Validator validator = schema.newValidator();
validator.validate(new StreamSource("sample.xml"));
}
}
|
|
33. 17. XML模式 | | 33. 17. 1. | 从XML架构创建XML校验器 | | |
|