Markup Languages & XML - BY VISHAL KAMTAM VENKATESH
What are markup languages?? Language that uses tags to define elements within a document. It is human-readable. The two most popular markup languages are HTML and XML.
What is HTML? HTML-Hyper text Markup Language. HTML is comprised of “elements” and “tags” Begins with and ends with Elements (tags) are nested one inside another: Tags have attributes: HTML describes structure using two main sections: and
Example HTML code: Hello World Hello World
Output:
How they work?
Representation of HTML as Parse Tree Hello World
Representation in CFG HTML can be described by classes of text Text is any string of characters literally interpreted (i.e. there are no tags, user-text) Char is any single character legal in HTML tags.Blanks included Element is Text or A pair of matching tags and the document between them, or Unmatched tag followed by a document Doc is sequences of elements ListItem is the tag followed by a document followed by List is a sequence of zero or more list items
HTML Grammar Char a | A | … Text ε | Char Text Doc ε | Element Doc Element Text | Doc | Doc | List ListItem Doc List ε | ListItem | List
HTML Example popular markup languages HTML XML The text can be viewed as : popular markup languages 1. HTML 2. XML
Extensible Mark-up languages (XML)
XML has user defined tags whereas HTML has predefined tags. designed to describe data, not to display data. eg: ” 12 Maple Street ” 12 Maple Street In most web applications, XML is used to describe data, while HTML is used to format and display the data.
Example XML Mary likes John.
PARSE TREE
PRODUCTION RULES → → Mary|John → believes → likes
XML’s DTD The DTD lets us define our own grammar Context-free grammar notation, also using regular expressions Form of DTD: Element definition:
Element Description Element descriptions are regular expressions Basis Other element names #PCDATA, for any TEXT without tags Operators | for union , for concatenation * zero or more occurrences of ? for zero or one occurrence of + for one or more occurrences of
Example DTD-1 <!DOCTYPE PcSpecifications [ ]>
Pc Specs XML Document 4560 $2295 Intel Pentium 4Ghz 8192 Maxtor Diamond 2000Gb 32x …..
DTD and Production Rules DTD: Production Rule: PROCESSOR MANF MODEL SPEED DTD: <!ELEMENT DISK (HARDDISK|CD|DVD) Production Rule: Disk HARDDISK|CD|DVD DTD:
Production Rule: PC AB A Model Price Processor Ram B Disk+ Last production is illegal.we introduce C B CB|C C Disk We can rewrite above expression PC Model Price Processor Ram B B Disk B|Disk
Example DTD-2 <!DOCTYPE SENTENCES [ }>
Production Rules (SENTENCE) (NOUN-PHRASE)(VERB-PHRASE) (NOUN-PHRASE) (CMPLX-NOUN)|(CMPLX-NOUN)(PREP-PHRASE) (VERB-PHRASE) (CMPLX-VERB)|(CMPLX-VERB)(PREP-PHRASE) (PREP-PHRASE) (PREP)(CMPLX-NOUN) (CMPLX-NOUN) (ARTICLE)(NOUN) (ARTICLE) A|THE (NOUN) BOY|GIRL|FLOWER (VERB) TOUCHES|LIKES|SEES (PREP) WITH
CONCLUSION DTD for both 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.
Reference Links:
THANKYOU!!!!!!