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

PHP XML compare

<p>One fact you must memorize whenever you want to create, <a href="/courses/video/47/399/Modifying-XML.html">modify</a>, parse or process information in an XML document: <b>everything is a character <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html">string</a></b>. There are no other content types in an XML document. This property ensures that XML remains universally flexible and compatible with a whole lot of software libraries written in different languages.</p> <p>There are a few interesting programming scenarios, regarding comparison of different <a href="/courses/video/47/366/Elements.html">XML elements</a> that belong to the SAME element category. A simple example XML document and the PHP code to process it, will make things crystal clear. Here's another real-life example:</p> <p>A crime has been committed and the NYPD officers are busy trying to match descriptions and clues of the suspect with police records in the database. Unfortunately, they don't have a photograph or scanned image of the suspect, but they do have a rough sketch drawn by the police artist, based on observations from onlookers. Facial features of the sketch are stored as elements in an XML profile in profile.xml as well as the official photo features. A program runs through the official files in the database looking for a match with the sketch XML file.</p> <p>The XML document format might be something like: </p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; </p> <p>&lt;profile&gt; </p> <p>&lt;nose shape=&quot;sharp&quot; width=&quot;narrow&quot; nostrils=&quot;large&quot; /&gt; </p> <p>&lt;eyes color=&quot;blue&quot; squint=&quot;yes&quot; /&gt; </p> <p>&lt;chin zits=&quot;yes&quot; many=&quot;no&quot; /&gt; &lt;chin cleft=&quot;yes&quot; large=&quot;no&quot; /&gt; </p> <p>&lt;hair color=&quot;blond&quot; long=&quot;no&quot; curls=&quot;yes&quot; /&gt; </p> <p>&lt;/profile&gt; </p> <p>Now the program matches suspect.xml with profile.xml for each criminal in police records. PHP code that would perform such operations would look like: </p> <p>&lt;? </p> <p>$suspect = simplexml_load_file(&quot;suspect.xml&quot;); </p> <p>$profile = simplexml_load_file(&quot;profile.xml&quot;); </p> <p>if((string)$profile-&gt;nose['shape'] == (string)$suspect-&gt;nose['shape']){ </p> <p>echo &quot;Suspect's Nose Shape Matches Record!&quot;; </p> <p>if(... ) </p> <p>//%u2026 you get the idea... </p> <p>} </p> <p>?&gt; </p> <p>Here, specific attribute values of two XML documents are being matched. If the &quot;shape&quot; <a href="/courses/video/47/368/Attributes.html">attribute</a> value of the suspect's &quot;nose&quot; element matches the corresponding value in the current profile being examined, a message gets displayed in the browser. Note that we have cast the value to <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html">string</a> type because the browser has no way to figure out the type that matches the expression being compared. Only one side of the comparison actually needs to be cast to string type: the other expression is automatically cast to string based on context. </p> <p>Note that if the same document is opened twice and stored in different <a href="/courses/video/4/153/What-Are-Variables.html">variables</a>, the two still aren't identical. At runtime, each has its own memory location, and a <a href="/courses/video/47/395/Loading-XML-in-PHP.html">PHP</a> check for equality will always return false. They can be used independently, without one being affected by changes to the other. </p> <p>&lt;? </p> <p>$xmlone = simplexml_load_file(&quot;profile.xml&quot;); </p> <p>$xmltwo = simplexml_load_file(&quot;profile.xml&quot;); </p> <p>echo ($xmlone == $xmltwo); // always returns false</p> <p>?&gt; </p> <p>If this code is executed, the browser renders a blank page.</p> <p>This is a very important observation. Don't worry if you're confused... run the video again and the explanations will be very useful in forming a mental picture. </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