Kiểm tra tài liệu XML ThS. Trần Minh Triết.

Slides:



Advertisements
Similar presentations
XML Document Type Definitions ( DTD ). 1.Introduction to DTD An XML document may have an optional DTD, which defines the document’s grammar. Since the.
Advertisements

1 XML DTD & XML Schema Monica Farrow G30
An Introduction to XML Schema CSCI 7818 by Ming Rutar.
A Simple Schema Design. First Schema Design Being a Dog Is a Full-Time Job Charles M. Schulz Snoopy Peppermint Patty extroverted beagle Peppermint.
1 XML Document Type Definitions XML Schema. 2 Well-Formed and Valid XML uWell-Formed XML allows you to invent your own tags. uValid XML conforms to a.
Thayer School of Engineering Dartmouth Class Overview DTD Project discussion Visual Studio.NET Assignment 1.
Internet Technologies1 More XML Schema The main source for these slides is “The XML Companion” by Bradley Other resources:
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
XML Verification Well-formed XML document  conforms to basic XML syntax  contains only built-in character entities Validated XML document  conforms.
Jennifer Widom XML Data XML Schema. Jennifer Widom XML Schema “Valid” XML Adheres to basic structural requirements  Also adheres to content-specific.
Jennifer Widom XML Data DTDs, IDs & IDREFs. Jennifer Widom DTDs, IDs & IDREFs “Well-Formed” XML Adheres to basic structural requirements Single root element.
XML Fundementals XML vs.. HTML XML vs.. HTML XML Document (elements vs. attributes) XML Document (elements vs. attributes) XML and RDBMS XML and RDBMS.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
Chapter 4: Document Type Definitions. Chapter 4 Objectives Learn to create DTDs Validate an XML document against a DTD Use DTDs to create XML documents.
CSE4500 Information Retrieval Systems XML Schema – Part 1.
Presentation XML. NET SEMINAR By: Siddhant Ahuja (SID)
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA.
1 herbert van de sompel CS 502 Computing Methods for Digital Libraries Cornell University – Computer Science Herbert Van de Sompel
Example Write the DTD rules for the following XML fragment. Kim 34 South Street NY USA Vice President $175,000 1.
XML - DTD Week 4 Anthony Borquez. What can XML do? provides an application independent way of sharing data. independent groups of people can agree to.
 XML DTD and XML Schema Discussion Sessions 1A and 1B Session 2.
Schemas 1www.tech.findforinfo.com. What is a Schema a schematic or preliminary plan Description of a structure, details... 2www.tech.findforinfo.com.
1/11 ITApplications XML Module Session 3: Document Type Definition (DTD) Part 1.
Document Type Definitions (DTD) A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. A DTD.
XML Schema. Why Validate XML? XML documents can generally have any structure XML grammars define specific document structures Validation is the act of.
Beginning XML 3 rd Edition. Chapter 4: Document Type Definitions.
Unit 10 Schema Data Processing. Key Concepts XML fundamentals XML document format Document declaration XML elements and attributes Parsing Reserved characters.
Exam II Syllabus uStorage & Buffer Management uIndexing: Btrees & Hash uMulti-dimensional Indexing uQuery processing (relational ops) uQuery optimization.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A.
Copyrighted material John Tullis 3/18/2016 page 1 04/29/00 XML Part 4 John Tullis DePaul Instructor
Rèn luyện nghiệp vụ sư phạm 3
CITA 330 Section 4 XML Schema. XML Schema (XSD) An alternative industry standard for defining XML dialects More expressive than DTD Using XML syntax Promoting.
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
eXtensible Markup Language
XML Schema.
ACG 4401 XML Schemas XML Namespaces XLink.
ACG 4401 XML Schemas XML Namespaces XLink.
Semistructured-Data Model
CMP 051 XML Introduction Session IV
Lecture 9 XML & its applications
Chapter 23: XML Database System concepts,6th Ed.
Database Systems Week 12 by Zohaib Jan.
XML Validation III Schemas
WEB SERVICES Nhóm trình bày: Nguyễn Văn Dũng . Nguyễn Quang Minh .
دانشكده مهندسي كامپيوتر
Chương 1: Khái quát về dự án đầu tư.
Design and Implementation of Software for the Web
Introduction to XML Extensible Markup Language
CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT
XML Data DTDs, IDs & IDREFs.
DTD and XML Schema.
XML מבוא כללי פרק ב' MCSD Doron Amir
CMP 051 XML Introduction Session III
XML Technologies X-Schema.
Introduction to XML Extensible Markup Language
Quản trị rủi ro Những vấn đề căn bản Nguyễn Hưng Quang 07/11/2015 NHẬT HOA IC&T.
Introduction to XML Extensible Markup Language
Optimising XML Schema for IODEF Data model
CIT 383: Administrative Scripting
Lecture 9 XML & its applications
Lecture 4 Introduction to XML Extensible Markup Language
Quick Introduction to DFDL
XML In Action With Oracle
XML Schema Diyar A. Abdulqder
Presentation transcript:

Kiểm tra tài liệu XML ThS. Trần Minh Triết

XmlValidatingReader Lớp đối tượng XmlValidatingReader: Ví dụ: public XmlValidatingReader(XmlReader); public XmlValidatingReader(Stream, XmlNodeType, XmlParserContext); public XmlValidatingReader(string, XmlNodeType, XmlParserContext); Ví dụ: XmlTextReader _coreReader = new XmlTextReader (fileName); XmlValidatingReader reader=new XmlValidatingReader (_coreReader);

Kiểm tra toàn bộ tài liệu XML private bool ValidateDocument (string fileName) { // Initialize the validating reader XmlTextReader _coreReader = new XmlTextReader(fileName); XmlValidatingReader reader = new XmlValidatingReader(_coreReader); // Prepare for validation reader.ValidationType = ValidationType.Auto; reader.ValidationEventHandler += new ValidationEventHandler(MyHandler); // Parse and validate all the nodes in the document while (reader.Read()) {} // Close the reader reader.Close(); return true; }

Kiểm tra toàn bộ tài liệu XML (tt) private void MyHandler ( object sender, ValidationEventArgs e) { // Logs the error that occurred PrintOut(e.Exception.GetType().Name, e.Message); }

Các loại kiểm tra Validation Type None Auto DTD Schema XDR

Phân tích cách xác định loại kiểm tra phù hợp string GetActualValidationType (XmlValidatingReader reader, string filename) { string realValidationType = ""; if (reader.ValidationType == ValidationType.Auto) { if (reader.NodeType == XmlNodeType.DocumentType) realValidationType = "Auto.DTD"; else { if(reader.SchemaType is XmlSchemaType) { XmlSchemaType xst = (XmlSchemaType) reader.SchemaType; string xsd = Path.GetFileName(xst.SourceUri); string doc = Path.GetFileName(filename); if (xsd == doc) realValidationType = "Auto.Schema.Inline"; realValidationType = "Auto.Schema.Ref ("+ xsd + ")"; } return realValidationType;

Quy trình kiểm tra

Kiểm tra một đoạn XML public XmlValidatingReader (Stream, XmlNodeType, XmlParserContext); (string, XmlNodeType, XmlParserContext);

Giới thiệu về DTD <?xml version="1.0" ?> <!DOCTYPE class SYSTEM "class.dtd"> <!-- Sample XML document (data_dtd.xml) using a DTD --> <class title="Applied XML Programming for .NET" company="DinoEsposito's Own Company" author="Dino Esposito"> <days total="5" expandable="true"> <day id="1">XML Core Classes</day> <day id="2">Related Technologies</day> <day id="3">XML and ADO.NET</day> <day id="4" optional="true">XML and Applications</day> <day id="5" optional="true">XML Interoperability</day> </days> </class>

Giới thiệu về DTD <!ELEMENT class (days)> <!ATTLIST class title CDATA #REQUIRED author CDATA #IMPLIED company CDATA #IMPLIED> <!ENTITY % Boolean "true | false"> <!ELEMENT days (day*)> <!ATTLIST days total CDATA #REQUIRED expandable (%Boolean;) #REQUIRED> <!ELEMENT day (#PCDATA)> <!ATTLIST day id CDATA #REQUIRED optional (%Boolean;) #IMPLIED>

Kiểm tra với DTD XmlTextReader _coreReader = new XmlTextReader("data_dtd.xml"); XmlValidatingReader reader = new XmlValidatingReader(_coreReader); reader.ValidationType = ValidationType.DTD; reader.ValidationEventHandler += new ValidationEventHandler(MyHandler); while (reader.Read()); --------------------------------------------------- private void MyHandler(object sender, ValidationEventArgs e) { if (e.Severity == XmlSeverityType.Error) { // Handle the schema exception }

Giới thiệu về XDR <?xml version="1.0" ?> <!-- Sample XML document (data_xdr.xml) using XDR --> <class xmlns="x-schema:Schema.xml" title="Applied XML Programming for .NET" company="Wintellect" author="DinoE"> <days total="5" expandable="true"> <day id="1">XML Core Classes</day> <day id="2">Related Technologies</day> <day id="3">XML and ADO.NET</day> <day id="4" optional="true">XML and Applications</day> <day id="5" optional="true">XML Interoperability</day> </days> </class>

Giới thiệu về XDR <?xml version="1.0"?> <Schema name="MyClass" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <!-- Attribute Types --> <AttributeType name="title" dt:type="string" /> <AttributeType name="company" dt:type="string" /> <AttributeType name="author" dt:type="string" /> <AttributeType name="total" dt:type="int" /> <AttributeType name="expandable" dt:type="enumeration" dt:values="true false" /> <AttributeType name="optional" dt:type="enumeration" <AttributeType name="id" dt:type="int" />

Giới thiệu về XDR <!-- Element Types --> <!-- CLASS --> <ElementType name="class" content="eltOnly" model="closed" order="seq"> <element type="days" minOccurs="1" maxOccurs="1" /> <attribute type="title" required="yes" /> <attribute type="author" required="no" /> <attribute type="company" required="no" /> </ElementType>

Giới thiệu về XDR <!-- DAYS --> <ElementType name="days" content="eltOnly"> <element type="day" minOccurs="1" maxOccurs="*" /> <attribute type="total" required="yes" /> <attribute type="expandable" required="no" /> </ElementType> <!-- DAY --> <ElementType name="day" content="textOnly"> <attribute type="id" required="yes" /> <attribute type="optional" required="no" /> </Schema>

Kiểm tra với XDR XmlTextReader _coreReader = new XmlTextReader("data_xdr.xml"); XmlValidatingReader reader = new XmlValidatingReader(_coreReader); reader.ValidationType = ValidationType.XDR; reader.ValidationEventHandler += new ValidationEventHandler(MyHandler); while (reader.Read()); --------------------------------------------------- private void MyHandler(object sender, ValidationEventArgs e) { if (e.Severity == XmlSeverityType.Error) { // Handle the schema exception }

Giới thiệu về Schema <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="address" type="AddressType" /> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="street" type="xs:string" /> <xs:element name="number" type="xs:string" /> <xs:element name="city" type="xs:string" /> <xs:element name="state" type="xs:string" /> <xs:element name="zip" type="xs:string" /> </xs:sequence> <xs:attribute name="country" type="xs:string" /> </xs:complexType> </xs:schema>

Kiểm tra với Schema XmlTextReader _coreReader = new XmlTextReader("data_xdr.xml"); XmlValidatingReader reader = new XmlValidatingReader(_coreReader); reader.ValidationType = ValidationType.Schema; reader.ValidationEventHandler += new ValidationEventHandler(MyHandler); while (reader.Read()); --------------------------------------------------- private void MyHandler(object sender, ValidationEventArgs e) { if (e.Severity == XmlSeverityType.Error) { // Handle the schema exception }