XML
  Home arrow XML arrow SimpleXML
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

SimpleXML
By: James Murray
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 44
    2004-06-22

    Table of Contents:
  • SimpleXML
  • Replace Tags with Our Data
  • Build List of Tags
  • Load the XML File and Output It
  • Putting it All to Use

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    SimpleXML
    (Page 1 of 5 )

    Learn an easy way to parse XML and output it the way you want by using the simpleXML extensions in PHP5. Murray outlines the 3 main elements of an XML document and how to replace them with your own non-template  data and how to build an array of all the tags put in the document.

    SimpleXML project primer:

    To the new PHP programmer, XML is quite the mysterious thing. Recently I began writing a website that uses an XML template system, so I needed to find an easy way to parse my XML, and output it the way I needed it to be outputted. With PHP4 you have to build your own XML parser that will read and output your XML. So, with that idea I decided begin to explore PHP5, because of its simpleXML extensions.

    Before jumping ahead and just building my parser, I knew that I’d have to replace elements in the XML document with data from my database; after all what would be the point of using XML for a template system if you couldn’t replace elements with your own data. So, keeping that in mind I know that I’d have to load each element of my XML document into a variable then send it through my own function to replace the things I need to replace, with the correct information. Now, let’s get started.

    The first thing we should look at is the XML document. This is a simpler version of mine, but it’s still the same basic idea. Save the following as template.xml.

    <?xml version="1.0" encoding="UTF-8" ?>
    <template>
      <header>
    <![CDATA[
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html xmlns="
    http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title><!title></title>
    </head>
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td style="text-align:center;"><!logo></td>
     </tr>
    </table>
      ]]>
      </header>
      <body>
    <![CDATA[
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
     <td width=”15%”><!column1></td>
     <td width=”70%”><!column2></td>
     <td width=”15%”><!column3></td>
    </tr>
    </table>
      ]]>
      </body>
      <footer>
    <![CDATA[
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
      <td style="text-align:center;"><!footer></td>
     </tr>
    </table>
    </body></html>
      ]]>
      </footer>
    </template>

    More XML Articles
    More By James Murray


     

       

    XML ARTICLES

    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway