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

Elements and Attributes in PHP

<h2>How to access elements and attribute values in PHP</h2> <p>We saw in the <a href="/courses/video/47/395/Loading-XML-in-PHP.html">previous summary</a>. that while we can directly output XML document data that is simply organized as a root element with content (and no nested elements within,) we aren't lucky enough to get such simply structured documents in everyday software tasks or projects. PHP language implementations provides syntactic constructs to work around the problem we saw previously; namely that elements with other nested elements draw a total blank when an attempt is made to render them.</p> <p>There are two main constructs provided:</p> <ol> <li>Accessing content in <a href="/courses/video/47/367/Nesting-Elements.html ">nested elements</a> using the '→' <a href="/course/basics/operators">operator</a></li> <li>Accessing attribute values using the '[]' indexing operator.</li> </ol> <p>Probably a live example would clarify the above statements. Consider an XML document that has the following information stored: a description of the chassis of an automobile. For example: </p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; </p> <p>&lt;automobile id=&quot;786&quot;&gt; </p> <p>&lt;model&gt;Volkswagen Jetta&lt;/model&gt; </p> <p>&lt;chassis&gt; </p> <p>&lt;battery model=&quot;amaron&quot; power=&quot;500W&quot;/&gt; </p> <p>&lt;radiator coolant=&quot;ethanol&quot;/&gt; </p> <p>&lt;engine model=&quot;VW1200&quot; capacity=&quot;1200cc&quot; hp=&quot;100&quot;/&gt; </p> <p>&lt;/chassis&gt; </p> <p>&lt;/automobile&gt; </p> <p>The PHP code sample given below explains how to extract all the information regarding the model name and engine specification of a car manufactured by a German automobile giant. Please read carefully... the syntax is very simple and intuitive... just try to visualize a tree structure:</p> <p>&lt;? </p> <p>$xml = simple_xml_load_file(&quot;auto.xml&quot;); </p> <p>echo $xml-&gt;automobile-&gt;model; </p> <p>echo $xml-&gt;automobile-&gt;chassis-&gt;engine[model]; </p> <p>?&gt; </p> <p>The output will be the value of the model element and the attribute value of model inside the engine element. A complication arises if the tag name of an XML element has the character '-' as part of the label. For example, if the attribute &quot;model&quot; of the element &quot;automobile&quot; were to be renamed as &quot;engine-model&quot;, then the statement to extract the model attribute would be changed. The name should be enclosed in double quotes, as in &quot;engine-model&quot;; unlike the other scenario, where we could use the attribute name un-quoted. </p> <p>So we can now handle both trivial as well as non-trivial XML document formats in <a href="/courses/video/47/395/Loading-XML-in-PHP.html">PHP</a>. Handling means loading, opening, parsing and processing. There are other useful <a href="/course/indispensable-as3/graphics-api.html">API</a>s for handling XML documents in the language, which we'll encounter in the following videos.</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