18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6<br />

SGML was used to define the Document Type Definition (DTD) for HTML, and it is still used to write<br />

DTDs for XML. The problem with SGML is its allowances for odd syntax, which makes creating parsers<br />

for HTML a difficult problem:<br />

❑<br />

❑<br />

❑<br />

❑<br />

Some start tags specifically disallow end tags, such as the HTML . Including an end tag<br />

causes an error.<br />

Some start tags have optional or implied end tags, such as the HTML , which assumes a<br />

closing tag when it meets another or several other tags.<br />

Some start tags require end tags, such as the HTML .<br />

Tags can be embedded in any order. <strong>For</strong> instance, This is a sample <br />

string is okay even though the end tags don’t occur in reverse order of the start tags.<br />

❑ Some attributes require values, such as src in .<br />

❑<br />

❑<br />

Some attributes don’t require values, such as nowrap in .<br />

Attribute can be defined with or without quotation marks surrounding them, so and are both allowed.<br />

All these issues make creating SGML language parsers a truly arduous task. The difficultly of knowing<br />

when to apply the rules caused a stagnation in the definition of SGML languages. This is where XML<br />

begins to fit in.<br />

XML does away with all the optional syntax of SGML that caused so many developers heartache early<br />

on. In XML, the following rules apply:<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

Every start tag must have end tag.<br />

An optional shorthand syntax represents both the start and end tags in one. This syntax uses a<br />

forward slash (/) immediately before the greater-than symbol, such as . An XML parser<br />

interprets this as being equal to .<br />

Tags must be embedded in an appropriate order, so end tags must mirror start tags, such as<br />

this is a sample string. It helps to think of start and end tags as similar<br />

to open and close parentheses in math: You cannot close the outermost parenthesis without first<br />

closing all the inner ones.<br />

All attributes require values.<br />

All attributes must use quotes around the values.<br />

These rules make an XML parser much simpler to develop and also remove the guesswork of when and<br />

where to apply odd syntax rules. Where SGML failed to gain mainstream acceptance, XML has made<br />

tremendous inroads because of its simplicity. XML has spawned several languages in just the first six<br />

years of its existence, including MathML, SVG, RDF, RSS, SOAP, XSLT, XSL-FO, and the reformulation<br />

of HTML into XHTML.<br />

<strong>For</strong> a technical comparison of SGML and XML, please see the W3C’s note located at http://<br />

www.w3.org/TR/NOTE-sgml-xml.html.<br />

160

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!