developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Promote Your Website
Computer Deals
Desktop Computers
Promotional Gifts
Boat Donations
Career Education
Phone Cards
Logo Design
KVM Switches
Memory
KVM Switch over IP
Corporate Awards
Imprinted Gifts
Compare Prices

 
Biz Resources
Technology Asset Management Software
Information Technology Services
ecommerce solutions


Web Devs:
Moonlight as a Game Developer and Win Cool Prizes by Accepting the RIA Run Challenge

Now, your mission--should you choose to accept: Take your shot at gaming stardom if you think you might have what it takes to build a cool RIA game and you could win an Xbox 360 or other fabulous prizes. Hurry! You only have until May 15, 2008 to enter. »

 
Article:
Leveraging Your Flash Development with Silverlight

You're not giving up Flash any time soon (and we don't blame you.) But if you could get your Flash application working in Silverlight, why wouldn't you? We show you the tools and techniques required to have your rockin' Flash application rolled for Silverlight. Learn more here. »

 
Article:
What Does it Take to Build the Best RIA?

With the proliferation of Rich Interactive Application (RIA) platform choices out there, you no longer have to take a one-size-fits-all approach to developing your next RIA application. Knowing the strengths (and weaknesses) of each platform can help you to decide the best RIA for your next application. »

 
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

The Story of a WML Generator
By Radu Braniste

Go to page: 1  2  3  Next  

This article presents a flexible, compile-time safe way of generating WML and WML-like dialects code. Two contrasting solutions are discussed—one relying on C# without generics and the other one on C++. A rarely used C# idiom is presented, increasing the reusability of the code, but C++ and templates related techniques confer the ultimate level of flexibility.

Throughout the article, WML is used as an example of an XML dialect imposing strict rules on the nesting of its elements, but otherwise any hierarchical based language fills the bill. That's why just a subset of WML is presented and the emphasis is mostly put on the flexible design of the hierarchy of elements and the validation of specific rules governing their composition.

A Short History

Although WML (Wireless Markup Language[1])—a XML-based content language developed in 1999 for WAP—probably will be phased out in the future, it still represents a good standardized example of how XML can be used to create a minimalist language, easy to generate and manipulate.

Generating WML code might look like an easy task, but generating valid WML code is something different. And when additional flexibility is required—to quickly move from WML to a related XML dialect governed by slightly different rules, for example—the task becomes even more daunting.

WML was designed for low-bandwidth, small-display devices and such as it concentrated on wireless transaction efficiency: an application (a deck) has screens (cards) that can be downloaded in bulk on the device and processed as needed. A number of predefined elements can be embedded in cards following a set of rules allowing specific combinations only (for example, from WML DTD 1.2:

<!ELEMENT wml ( head?, template?, card+ )>
<!ELEMENT card (onevent*, timer?, (do | p | pre)*)>
<!ELEMENT go (postfield | setvar)*>

Taking care of all these rules and generating valid WML code is the first goal of your endeavor.

The First Step: C#

You can start with a first implementation attempt, written in C# [3]. Just a subset of WML was used and compositional rules are for demonstrational purpose only [4]:

namespace mlgen
{
   class GenericElement
   {
      public
      GenericElement(string element, string init)
      {
         root_ = init;
         element_ = element;
         inserted_ = false;
         used_ = false;
         openElement();
      }
      public GenericElement(string element) : this(element,
                                                   string.Empty)
      {}
      public override string ToString()
      {
         closeElement();
         return root_;
      }
      protected void genericInsert(GenericElement e)
      {
         whenInserted();
         root_ += e;
      }
      protected void genericAddProperty(string key, string value)
      {
         if (!inserted_)
         {
            root_ += " "
            root_ += key;
            root_ += "="";
            root_ += value;
            root_ += """;
         }
      }
      private void openElement()
      {
         root_ += "<";
         root_ += element_;
      }
      private void whenInserted()
      {
         if (!inserted_)
         {
            root_ += ">";
            inserted_ = true;
         }
         root_ += 'n';
      }
      private void closeElement()
      {
         if (used_)
            return;
         used_ = !used_;
         if (inserted_)
         {
            root_ += 'n';
            root_ += "</";
            root_ += element_;
            root_ += ">";
         }
         else
         {
            root_ += "/>";
         }
      }
      private string root_;
      private readonly string element_;
      bool inserted_;
      bool used_;
   };
   class BreakImpl : GenericElement
   {
      public
         BreakImpl() : base("br")
      { }
   };
   class HeadImpl : GenericElement
   {
      public
         HeadImpl() : base("head")
      { }
      public void insert(BreakImpl e)
      {
         genericInsert(e);
      }
   };
   class ParagraphImpl : GenericElement
   {
      public
         ParagraphImpl() : base("p")
      { }
      };
      class CardImpl : GenericElement
      {
         public
            CardImpl() : base("card")
         {}
         void setID(string id)
         {
            genericAddProperty("id", id);
         }
         public void insert(ParagraphImpl e)
         {
            genericInsert(e);
         }
      };
      class DeckImpl : GenericElement
      {
         public
            DeckImpl() : base("wml",
            "<?xml version="1.0"?>n<!DOCTYPEwml PUBLIC };
              -//PHONE.COM//DTD WML 1.1//EN"n
              "http://www.phone.com/dtd/wml11.dtd" >n" )
            { }
         public void insert(CardImpl e)
         {
            genericInsert(e);
         }
         public void insert(HeadImpl e)
         {
            genericInsert(e);
         }
      };
}

Go to page: 1  2  3  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Techniques Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Learn about expanding business opportunities for the reseller channel. Visit IT Channel Planet.
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Whitepaper: XML Processing in Applications--Take the Next Step



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES