XMDP and C#

10/31/2008

If you've done any sort of web development, you've most likely used the meta tag. You've probably put in there the copyright info, who created the document, basically Google/other crawler specific info for the most part as no one really reads it. Its purpose in everything though is to give meta information to some program. However, what if you wanted to have meta information within the web page itself (think Microformats)? It's possible, use rel, class, id, etc. to define items that are of a specific type and use CSS to make it look decent. However no one will know what those tags mean and no computer will know what they are. Thus they'll be ignored. So how could you define these items in a document that could be shared and read by both a human and a machine? Well that's where XMDP comes in.

XMDP, or XHTML Meta Data Profile, is a very simple format that can be used to define the meta data that are used on your pages. It's been used for pretty much all of the various microformats out there (hCard for example). So it is in use and like I said it's extremely simple (it's basically just a dictionary pairing of items and their descriptions using dl, dt, and dd). And to make your lives even easier when it comes to creating XMDP pages, I've created a couple of classe to help you out:

XMDP.cs

   1: /*
   2: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
   3: 
   4: Permission is hereby granted, free of charge, to any person obtaining a copy
   5: of this software and associated documentation files (the "Software"), to deal
   6: in the Software without restriction, including without limitation the rights
   7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   8: copies of the Software, and to permit persons to whom the Software is
   9: furnished to do so, subject to the following conditions:
  10: 
  11: The above copyright notice and this permission notice shall be included in
  12: all copies or substantial portions of the Software.
  13: 
  14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20: THE SOFTWARE.*/
  21:  
  22: #region Usings
  23: using System.Collections.Generic;
  24: using System.Text;
  25: #endregion
  26:  
  27: namespace Utilities.FileFormats.XMDP
  28: {
  29:     /// <summary>
  30:     /// Class for creating XMDP pages
  31:     /// </summary>
  32:     public class XMDP
  33:     {
  34:         #region Constructor
  35:  
  36:         /// <summary>
  37:         /// Constructor
  38:         /// </summary>
  39:         public XMDP()
  40:         {
  41:             Properties = new List<Property>();
  42:         }
  43:  
  44:         #endregion
  45:  
  46:         #region Properties
  47:  
  48:         /// <summary>
  49:         /// Properties to be included
  50:         /// </summary>
  51:         public List<Property> Properties { get; set; }
  52:  
  53:         #endregion
  54:  
  55:         #region Overridden Functions
  56:  
  57:         public override string ToString()
  58:         {
  59:             StringBuilder Builder = new StringBuilder();
  60:             Builder.Append("<dl class=\"profile\">");
  61:             foreach (Property Property in Properties)
  62:             {
  63:                 Builder.Append(Property.ToString());
  64:             }
  65:             Builder.Append("</dl>");
  66:             return Builder.ToString();
  67:         }
  68:  
  69:         #endregion
  70:     }
  71: }

Property.cs

   1: /*
   2: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
   3: 
   4: Permission is hereby granted, free of charge, to any person obtaining a copy
   5: of this software and associated documentation files (the "Software"), to deal
   6: in the Software without restriction, including without limitation the rights
   7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   8: copies of the Software, and to permit persons to whom the Software is
   9: furnished to do so, subject to the following conditions:
  10: 
  11: The above copyright notice and this permission notice shall be included in
  12: all copies or substantial portions of the Software.
  13: 
  14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20: THE SOFTWARE.*/
  21:  
  22: #region Usings
  23: using System.Collections.Generic;
  24: using System.Text;
  25: #endregion
  26:  
  27: namespace Utilities.FileFormats.XMDP
  28: {
  29:     /// <summary>
  30:     /// Class for holding the individual properties and their
  31:     /// descriptions.
  32:     /// </summary>
  33:     public class Property
  34:     {
  35:         #region Constructors
  36:  
  37:         /// <summary>
  38:         /// Constructors
  39:         /// </summary>
  40:         public Property()
  41:         {
  42:             Properties = new List<Property>();
  43:         }
  44:  
  45:         #endregion
  46:  
  47:         #region Properties
  48:  
  49:         /// <summary>
  50:         /// Name of the property
  51:         /// </summary>
  52:         public string Name { get; set; }
  53:  
  54:         /// <summary>
  55:         /// Description of the property
  56:         /// </summary>
  57:         public string Description { get; set; }
  58:  
  59:         /// <summary>
  60:         /// List of sub properties (only used for rel type when you need to
  61:         /// define new link types)
  62:         /// </summary>
  63:         public List<Property> Properties { get; set; }
  64:  
  65:         #endregion
  66:  
  67:         #region Overridden Functions
  68:  
  69:         public override string ToString()
  70:         {
  71:             StringBuilder Builder = new StringBuilder();
  72:             Builder.Append("<dt id=\"" + Name + "\">" + Name + "</dt>");
  73:             if (Properties.Count > 0)
  74:             {
  75:                 Builder.Append("<dd><dl>");
  76:                 foreach (Property Property in Properties)
  77:                 {
  78:                     Builder.Append(Property.ToString());
  79:                 }
  80:                 Builder.Append("</dl></dd>");
  81:             }
  82:             else
  83:             {
  84:                 Builder.Append("<dd>" + Description + "</dd>");
  85:             }
  86:             return Builder.ToString();
  87:         }
  88:  
  89:         #endregion
  90:     }
  91: }

Just two classes, each is documented, etc.  So give it a try, leave feedback, and happy coding.



Comments