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

UNIX System Administrator - SUN Solaris, Veritas, EMC, Shell Scripting, SAN (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow


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]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark

Created: September 3, 2002
Revised: September 3, 2002

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