Question 1
Have a look at the documents below, some are XML documents, some are HTML documents, some may be neither. See if you can decide which are which.
Document 1
This document is an HTML document, it is constructed with some of the well known HTML tags such as <head>, <title>, <body>, <a> etc… It also includes a <script> tag example which is used to load javascript code. Most HTML tags include attributes such as <a href=” http://ads.touregypt.net/cgi-bin/adcycle/adclick.cgi?gid=1&id=305”> which would be rendered as a hyperlink, linking to http://ads.touregypt.net/cgi-bin/adcycle/adclick.cgi?gid=1&id=305 or <table border=”0”> which would style the table with no border. The latter would be better implemented using a cascading style sheet CSS to have distinct documents for content and styling. As it is this document can not be validated as an HTML document as some obvious flaws exist such as document does not have an <HTML> tag which is the root tag for all HTML documents. There are also various tags which are not terminated properly such as the <table border=”0” width=570””> tag.
Document 2
This document is a VALID XML document, although this document follows correct XML syntax, it could not be validated against the referenced DTD schema as this was not supplied.
Document 3
This document is an HTML document, very similar to Document 1, which although makes use of valid HTML tags could not be considered valid XML because of missing <HTML> tags etc.. This document also includes an example of the <script> tag, this time in the header; this is considered better practice than loading javascript in the <body> section as it ensures the script is loaded before the document body. A <form> element is also used in this document, <form> elements allow browsers to capture and forward user inputted data.
Document 4
This document is a VALID XML document; it follows correct XML syntax but cannot be validated against the referenced DTD schema as this was not supplied with the example.
Document 5
This document is an XML document, the first section of the document is the DTD schema which defines the structure of the XML content whilst the second portion of the document is the XML document itself which references the DTD used to validate it.
Document 6
This document is a VALID XML document; it follows correct XML syntax but cannot be validated as the referenced schema was not provided with the examples.
Document 7
This is an HTML document, although most tags defined in this document do not appear to be proper HTML tags such as <OfficialName> & <commonName>, on closer inspection one would notice that these declarations are being passed as string through javascript functions which are then interpreting the data and generating the XML to be rendered to a browser.
Question 2
Make a list of the distinctive characteristics of an XML document, in terms of things that you can spot when looking at the code.
Answer
- Unlike HTML XML is not limited by a defined set of tags, XML is customizable.
- Although not strictly required XML documents have corresponding DTD or XSD schemas to be validated against
- All tags should be follows by corresponding closing tags e.g. <tag>content</tag> or closed immediately e.g. <tag />.
- XML documents should have one root element.
- XML tags may contain attributed within the tag e.g. <tag attribute=”value”>
- Content in XML documents escaped properly otherwise the document may become invalidated e.g. <tag>content > here</tag> is invalid XML the “>” is considered as a special character in XML and should be escaped as follows <tag>content > here</tag>
No comments:
Post a Comment