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

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use


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]

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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

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