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 Reviews  
Web Hosting Security  
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
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
     
     

    SEARCH WEB HOSTERS

    TOOLS YOU CAN USE

    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

    - Phishing Scams: An Overview and How to Detec...
    - Tips for Safe Downloading Online
    - How To Avoid Spam
    - How to Get Into Ethical Hacking
    - How to Prevent Drive-by Downloads
    - Facebook Timeline Tips and Tricks
    - How to Keep Up with Facebook`s Changes
    - Wi-Fi Network Security Tips
    - Tips for Safe Online Holiday Shopping
    - Facebook Privacy: Keeping Up with the Const...
    - Tips for Facebook Privacy
    - How to Cover Your Tracks on the Web
    - SSH Keys for FileZilla and Putty in Cpanel
    - How to Create a Filezilla FTP User
    - How to Install FileZilla Server

    Developer Shed Affiliates

     




    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap