spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / php4xml / chap10 / 1 current pageTo page 2To page 3To page 4To page 5To page 6To page 7
[next]

Professional PHP4 XML

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Programming XML Applications

With a very broad vision we may classify programming tasks using XML into two major categories:

Storing and retrieving XML is detailed in Chapter 13.

Up till now in this book we've covered the core standards for XML processing--XPath, SAX, DOM, and XSLT. In this chapter we are going to study different XML processing problems and study different solutions to these problems using the tools we've mastered in the previous chapters.

We need to process XML data from some source since it is useful to our application. We are going to study some very common problems that arise when processing an XML document. For each problem we'll discuss different options to solve the problem and the scenarios where each solution is better than the others.

The assumption here is that we are in the middle of a large application, and maintaining it is an important issue, hence, we'll be focusing on OOP solutions most of the time. We'll also observe some patterns of OOP that can be applied to programs that process XML.

Transforming XML

When it comes to transforming XML, we have an XML file or XML data source that we need to transform. This can be achieved in many different ways, for example:

Transforming implies reading XML, peeking at the content, and writing something that may or may not be XML.

Example

To illustrate different solutions, we'll work with a very simple example. Let's use the following XML file describing some applications coded by a software company:

<?xml version="1.0" ?>
<!-- This XML file is an example -->
<apps>
<application id="1">
  <name>Editor</name>
  <author>John</author>
  <bugs>
    <bug>
      <!-- This is one bug -->
      <desc>Foo</desc>
      <sev>2</sev>
    </bug>
    <bug>
      <desc>Bar</desc>
      <sev>3</sev>
    </bug>
  </bugs>
</application>
<application id="2">
  <name>Compiler</name>
  <author>Peter</author>
  <bugs>
    <bug>
    <desc>Foo Bar</desc>
    <sev>5</sev>
    </bug>
  </bugs>
</application>
</apps>

Our transformation task will be to transform all the <name> elements to a <name><b>text</b></name> format where all the text is uppercase. After transformation, the sample file would look like this:

<?xml version="1.0" ?>
<!-- This XML file is an example -->
<apps>
<application id="1">
  <name><b>EDITOR</b></name>
  <author>John</author>
  <bugs>
    <bug>
      <!-- This is one bug -->
      <desc>Foo</desc>
      <sev>2</sev>
    </bug>
    <bug>
      <desc>Bar</desc>
      <sev>3</sev>
    </bug>
  </bugs>
</application>
<application id="2">
  <name><b>COMPILER</b></name>
  <author>Peter</author>
  <bugs>
    <bug>
    <desc>Foo Bar</desc>
    <sev>5</sev>
    </bug>
  </bugs>
</application>
</apps>

We can transform XML documents using:


home / programming / php / php4xml / chap10 / 1 current pageTo page 2To page 3To page 4To page 5To page 6To page 7
[next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: August 12, 2002
Revised: August 12, 2002

URL: http://webreference.com/programming/php/php4xml/chap10/1/