90 likes | 228 Views
The connection between Context-free grammars and XML. Guðmundur Freyr Jónasson. Context-Free Grammars. Variables: A, B Terminals: 0, 1, # Nr of rules: 3. Derivation of the string 000#111 :. Document Type Definition (DTD).
E N D
The connection between Context-free grammars and XML Guðmundur Freyr Jónasson Algorithms, Logic and Complexity
Context-Free Grammars Variables: A, B Terminals: 0, 1, # Nr of rules: 3 Derivation of the string 000#111: Algorithms, Logic and Complexity
Document Type Definition (DTD) • DTD defines the legal building blocks of an XML document with a list of legal elements and attributes. • XML validity requires that a document follows the constraints expressed in its document type definition, which provides a rough equivalence to a context-free grammar for a document type. • DTD is specified using “Extended Context-Free Grammar”. Algorithms, Logic and Complexity
Extended Context-Free Grammar • Allows regular expressions over terminals and non-terminals on the right hand side of productions. • The regular expression operators are ∪, * and concatenation. • We could write grammar G as follows: Or Where S is the start symbol in both cases. Algorithms, Logic and Complexity
DTD Syntax • < !ELEMENT name (model) > • ELEMENT is a keyword • name is the the element name being declared • model is the elements content model • The content model is specified using a regular expression over element names. • We now have sequences of element names rather then sequences of symbols (strings) like in CFG. Algorithms, Logic and Complexity
Regular Expressions vs. DTD Syntax Algorithms, Logic and Complexity
CFG and DTD example Algorithms, Logic and Complexity
Conclusion • Both DTD for XML and CFG describe languages with certain rules and restrictions, and thereby declare what’s legal and what’s not in a given language. • An XML document is considered valid if it’s well formed and has been validated against a DTD. • A string is a valid string in a given Context-free language if the Context-free grammar for that language can generate it. Algorithms, Logic and Complexity
References • Introduction to the Theory of Computation, 2nd edition, M. Sipser, Course Technology, 2005. • W3Schools – Learn DTD: http://w3schools.com/dtd/default.asp • Extensible Markup Language (XML) Fourth Edition: http://www.w3.org/TR/REC-xml/ • Languages, Grammars and DTDs: http://www.dcs.bbk.ac.uk/~ptw/teaching/dtd-new/notes.html Algorithms, Logic and Complexity