spacer

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

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

Professional PHP4 XML, Chapter 10: Putting It Together

Data Center Architect
The Computer Merchant, Ltd
US-MA-chelsea

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Writing XML

[The following is the conclusion 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).]

Writing XML is a problem where an XML file has to be generated from a non-XML source (or it will be a transformation). For example, we may have some data in a database, a file, or objects, and we have to write an XML document. What we do with the XML document later is beyond the scope of the problem. Following are some instances of this problem:

  • We have data in a relational database and want to produce an XML representation of the data
  • We have data in a plaintext file that describes news and want to produce an XML RSS file
  • We have some PHP objects and want to produce an XML file describing object properties
  • We have a file in a proprietary format and want to convert it to XML for processing

We won't cover in this problem parsing the non-XML data, which is usually harder than writing the XML document.

Example

In this example we have the following text file describing a to-do list for some people:

Jim Smith, Go to the library and pick up books
Sidney, Make 13 copies of memo no:19
Kelly, Distribute memo no:5 by email
Sidney, Arrange meeting with foo managers
Kelly, Write a draft of the technical document for project X
Jim Smith, Distribute books to team members
Sidney, Record book loans in HR software

Our task is to generate a representation such as the following:

<to-do>
  <person>
    <name>Jim Smith</name>
    <tasks>
      <task>Go to the library and pick up books</task>
      <task>Distribute books to team members</task>
    </tasks>
  </person>
  
  <person>
    <name>Sidney</name>
    <tasks>
      <task>Make 13 copies of memo no:19</task>
      <task>Arrange meeting with foo&foo managers</task>
      <task>Record book loans in HR software</task>
    </tasks>
  </person>
  
  <person>
    <name>Kelly</name>
    <tasks>
      <task>Distribute memo no:5 by email</task>
      <task>Write a draft of the technical document for project X</task>
    </tasks>
  </person>
</to-do>

We can use the following tools to write XML documents:


home / programming / php / php4xml / chap10 / 4 current pageTo page 2To page 3To page 4To page 5
[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: September 3, 2002
Revised: September 3, 2002

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