spacer

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

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

Professional PHP4 XML, Chapter 10: Putting It Together

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

Modifying XML

[The following is a continuation of our series of excerpts from chapter 10 of the Wrox Press title, Professional PHP4 XML. Source code for the examples discussed can be downloaded at the Wrox Web site (free e-mail registration required).]

Modifying XML is a problem where we have an XML data source and need to modify it. We may want to change some text, add an attribute, add an element, or remove a subtree of the document.

Modifying is a subset of the transforming problem since the output is always XML, and belongs to the same vocabulary as the original file.

Here are some situations where we might find instances of this problem:

Example

For example, let's imagine we use XML to keep track of a shopping cart in some online store application. We may face a simple XML such as:

<cart>
  <user uid="382378">
    <name>John Smith</name>
  </user>
  <products>
    <product pid="12">
      <name>ACMEPencilHB</name>
      <desc>Soft Pencil by ACME</desc>
      <quantity>2</quantity>
      <unit_price>0.50</unit_price>
    </product>

    <product pid="13">
      <name>ACMEPen089</name>
      <desc>Rollerball pen</desc>
      <quantity>1</quantity>
      <unit_price>1</unit_price>
    </product>

  </products>
</cart>

Customers will use an interface to add/remove products from the shopping cart, and we have to reflect those changes to the XML file. Therefore, we'll need a way to:

Of course we should need more functions for our shopping cart to be usable, but let's use only these three for our examples.

When modifying XML is our task, the options are:


home / programming / php / php4xml / chap10 / 2 current pageTo page 2To page 3To page 4
[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 >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji

Created: August 19, 2002
Revised: August 19, 2002

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