Web Hosting How-Tos
  Home arrow Web Hosting How-Tos arrow Page 2 - Building a CMS, part 2: Taking it to t...
Web Hosting Articles  
Web Hosting FAQs  
Web Hosting How-Tos  
Web Hosting News  
Web Hosting Security  
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
ASP Web Hosting  
ASP.NET Web Hosting 
Budget Hosting 
Coldfusion 
Colocation 
Mobile Linux 
APP Generation ROI 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Reseller Web Hosting 
Shared Hosting 
Small Business Hosting 
Virtual Private Servers 
Windows Web Hosting
 
 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? 
WEB HOSTING HOW-TOS

Building a CMS, part 2: Taking it to the server
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 1
    2005-03-30

    Table of Contents:
  • Building a CMS, part 2: Taking it to the server
  • Generating the XML
  • Creating the Markup
  • A Word About Namespaces
  • PHP XSLT

  • 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


    Building a CMS, part 2: Taking it to the server - Generating the XML


    (Page 2 of 5 )

    There is one more thing we need to do before we send our form data to the server. Each company description needs XML markup added to it. Alternatively, we could generate new hidden form fields for each description or use some sort of delimiters to separate each description in a single hidden field; we could then add all XML tags at the server. It doesn't take much, however, to just add the XML we need using Javascript just before we send it all to the server.

    function subToServer()
    {
       var form = document.forms.release;//get the form object
       var descField = form.desc;//get the hidden form field for sending descriptions
       var descStr = "";
       if(descriptionObj)//if the user did some editing
       {
          var len = descriptionObj.desc_Arr.length;//how many do we have
          for(var i = 0;i < len;i++)
          {
             descStr += "<header>" + descriptionObj.head_Arr[i] + "</header>\n";
             descStr += "<description>" + descriptionObj.desc_Arr[i] + "</description>\n";
          }
       }
       else// if no editing was done use defaults
       {
          descriptionObj = new description(null,null);
          descStr += "<header>" + descriptionObj.descHead + "</header>\n" +
          "<description>" + descriptionObj.descText + "</description>\n";
       }
       descField.value = descStr;//put the data in the hidden field
       return true;//send it to the server
    }

    This function is called by the onSubmit event of the form. Returning true gives the go ahead to post the form.

    <form action="dxml.php"
    method="post"
    enctype="multipart/form-data"
    name="release"
    onSubmit="return subToServer()">

    Taking it to the Server

    Now we move to the server side PHP code. First let's set up an associative array that contains the markup for each of the features of the document. Since we are dealing with XML, we will need the required XML declaration at the top.

    $xml_arr["doctop"] = "<?xml version=\"1.0\"?".">\n".
    "<?xml-stylesheet href=\"release.css\" type=\"text/css\"?>\n";

    One important thing to note about using PHP with XML and XHTML documents is that, because XML declarations use a "<? ...... ?>" syntax, you will need to echo these lines, instead of leaving them in the document as markup. If the PHP interpreter hits this markup it will produce a parse error.

    You will also notice in the above example that we have a CSS style sheet declaration. Current XML aware browsers allow you to use CSS to style XML elements. There is no link or style element in XML, so instead you use the xml-stylesheet declaration. Serving our XML press release in CSS styled XML isn't the best idea if we want all browsers to render it properly, but it serves us well for testing purposes before we add the XSL transformation code.

    In styling XML elements it's important to realize that the browser knows nothing about them. This means that you will be using the CSS display property for each element to indicate to the browser whether an element is to be displayed as a block, inline or whatever other values are supported by the browser you are using. Some browsers also require a DTD (document type definition) to render XML.

    More Web Hosting How-Tos Articles
    More By Chris Root


     

    WEB HOSTING HOW-TOS ARTICLES

    - Connecting to a Server using SSH: the Fundam...
    - How to Expand a Simple Website
    - Practical Virtualization with VirtualBox
    - Other Uses for Your Web Hosting Server
    - Hosting Your Own Website: Reliability
    - Introduction to Hosting Websites
    - Choosing a Website Host
    - How to Choose a Budget Web Host
    - URL Redirection
    - How to Link a Domain Name to a Dynamic IP
    - How to Set up a Simple Website
    - Choosing the Right Kind of Web Hosting
    - Introduction to Choosing the Right Web Host
    - Strategies for Creating Domain Names
    - How to Pick Domain Names






    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT