02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoPrevious Video

XML Validation

<p>&quot;Life is like a box of chocolates. You never know what you&apos;ll find inside!&quot; </p> <p>(A famous line from the brilliant Oscar-winning movie &quot;Forrest Gump.&quot;)</p> <p>Yes, life is full of surprises and uncertainties, and this is the reason life has a charm to it. But programmers and software clients don't like surprises… especially the bad kind! And the same holds for information that is processed by programs.</p> <p>Software programs can work only when they can find structure and patterns in information, and XML was invented to help with that. So, validation of XML documents is also important. In particular, the syntactic structure of XML documents should be the same as expected by a computer program calling it. It is then considered &quot;well-formed.&quot; As we saw in an earlier session, correct matching of start and end tags for each <a href="/courses/video/47/366/Elements.html">element</a>, as well as correct <a href="/courses/video/47/367/Nesting-Elements.html">nesting of elements</a> (without overlap) are the main issues here.</p> <p>Consider, for example, a brothel owner who has to open a box of condoms, check that the contents are as expected – none are damaged or missing, before selling it in his brothel. If we were to describe this scenario in terms of a computer program that is given an XML document, we would say:</p> <ol> <li>The brothel owner : the browser&apos;s XML parser application</li> <li>The box of condoms: The XML document. Each type of rubber is an element category in the XML document.</li> <li>The brothel: the browser that accesses this XML doc stored on the web server, and displays the contained information on the browser interface.</li> </ol> <p>First, let us define a well-formed XML document that represents the box of condoms:</p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; </p> <p>&lt;box&gt; </p> <p>&lt;boxOfRubbers&gt; </p> <p>&lt;rubber id=&quot;0&quot;&gt; </p> <p>&lt;rubberName&gt;Ribbed&lt;/rubberName&gt; &lt;quantity&gt;4&lt;/quantity&gt; </p> <p>&lt;/rubber&gt; </p> <p>&lt;rubber id=&quot;1&quot;&gt; </p> <p>&lt;rubberName&gt;Glow in the Dark&lt;/rubberName&gt; </p> <p>&lt;quantity&gt;3&lt;/quantity&gt; </p> <p>&lt;/rubber&gt; </p> <p>&lt;rubber id=&quot;2&quot;&gt; </p> <p>&lt;rubberName&gt;Chocolate Flavored&lt;/rubberName&gt; </p> <p>&lt;quantity&gt;4&lt;/quantity&gt; </p> <p>&lt;/rubber&gt; </p> <p>&lt;/boxOfRubbers&gt; </p> <p>Now, when the brothel owner (browser&apos;s XML parser) opens (parses/scans and separates) the box of rubbers (XML document,) he might find one or more of the following inside: </p> <ol> <li>A few rubbers have melted (similar to no proper nesting of element start- and end- tags.) In other words, our xml is not well formed.</li> <li>A few items, (for example all the ribbed rubbers – say THAT 3 times very fast!) are missing. Could have been stolen by a picky hooker. Again, not well formed.</li> <li>All types and quantities of condoms advertised on the box cover are intact. In this case, the XML doc is well formed.</li> </ol> <p>If the brothel owner discovers that the box of rubbers is incomplete (not well formed,) then they do not sell them to clients. Instead, they return the box to the store where they bought them, along with some harsh words, and demand a refund. Similarly, if the browser&apos;s XML parser discovers that the document is not well formed, it displays an <a href="/courses/video/4/155/Error-1067-Implicit-Coercion.html">error</a> on the browser window. The creator of the document must then correct the syntactic structure. </p> <p>Hope we&apos;ve conveyed to you the importance of having a valid XML document for well-behaved, consistent software applications, so that they can earn you good money!</p>

Overview and Context of XML

We will learn about the historical perspective and overview of the XML standard. The main focus is on Information organization and cross platform usage

12:47

XML Elements

The first step in learning about how XML documents are structured is to get familiar with elements, the basic components of an XML document.

08:22

XML Nested Elements

Nested elements allow for complex data to be represented effortlessly in an XML document.

09:19

Attributes

Attribute-value pairs are an alternative to nesting of elements in an XML document. We'll see the pros and cons of this feature

08:12

More Then Just Leftovers

Comments, White-space, Special characters, Version Information and Parser by-passing content; we discuss what these constructs are and how to use them effectively

13:54

XML Validation

XML documents should be well formed structure- and content-wise for applications to be configured and behave properly. We discuss an analogy with a real life scenario to highlight the point

08:17

E4X – ActionScript 3.0

We describe the importance and beneficial features of E4X library, and why it should be used in browsers at the earliest

24:56

XML DOM

An XML document is often pictured as an inverted nodes (elements) tree and connected nodes have a relation between them. DOM allows the program to traverse and retrieve these related nodes.

11:12

JavaScript

We describe the basic syntax of Javascript to load XML documents in client-side applications

13:51

Looping XML

We describe the looping constructs of PHP scripting language and how they can be used to parse and render XML information in client software

14:19

XML as a Remote

We describe the utility of XML for the modern web, especially when there's a plethora of programming languages and platforms and how XML builds several bridges

09:19

Loading XML in PHP

We describe how to load XML documents into server side applications in the PHP scripting language

04:57

Elements and Attributes in PHP

We describe how to access elements and attribute values while processing XML content via PHP scripts in server-side software

04:44

foreach

We describe the foreach looping construct in PHP and also how it can be used to process XML documents in server-side software

07:01

PHP XML compare

We describe how to compare XML document components and content in different documents having the same syntax

05:08

Modifying XML

We describe how to modify the content of XML documents in PHP : insertion/deletion/update operations in server-side applications

08:34