Thursday, August 14, 2014

Use validator to validate xml against a shema

Demo: Create a program that accepts two command line parameters. The first parameter must specify the name of an XML document and the second parameter must specify the name of a schema. The program should validate the XML document against the specified schema by creating a DOM source on the
document.
Bước 1: Tạo new project



Bước 2: Tạo file shiporder.xml


Bước 3: Tạo file shiporder.xsd


Bước 4: Viết code cho file main


kết quả


Demo: ValidatorDOMDemo

Demo :Create a program that accepts two command line parameters. The first parameter must specify the name of an XML document and the second  parameter must specify the name of Schema. The program must also validate the XML document against the specified schema by creating a SAX source on the 
document.

Bước 1: Tạo new project



Bước 2: Tạo file shiporder.xml


Bước 3: Tạo file shiporder.xsd

 
Bước 4: Viết code cho file main
code DefaultHandler


code chạy chương trình


kết quả


Demo:ValidatorSAXDemo

Nhận xét:
- Validator là một cách cao hơn để kiểm soát lỗi của một file xml
- Nó không chỉ check xem một file xml có thực sự chuẩn theo quy tắc hay không, nó còn kiểm tra một file xml có thỏa mãn một schema nào đó hay không
- Chương trình được an toàn hơn

No comments:

Post a Comment