1 / 9

The connection between Context-free grammars and XML

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).

Download Presentation

The connection between Context-free grammars and XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The connection between Context-free grammars and XML Guðmundur Freyr Jónasson Algorithms, Logic and Complexity

  2. Context-Free Grammars Variables: A, B Terminals: 0, 1, # Nr of rules: 3 Derivation of the string 000#111: Algorithms, Logic and Complexity

  3. 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

  4. 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

  5. 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

  6. Regular Expressions vs. DTD Syntax Algorithms, Logic and Complexity

  7. CFG and DTD example Algorithms, Logic and Complexity

  8. 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

  9. 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

More Related