Share via


MCML Syntax for Elements and Attributes

MCML maps Common Language Runtime (CLR) objects to Extensible Markup Language (XML) elements, and CLR properties to XML attributes. MCML uses a nested structure, using inline or expanded syntax, in which an element contains an attribute, which in turn contains elements with their own nested attributes, and so forth:

<Element>
  <Attribute>
    <Element>
      <Attribute>
      ...

The following example shows how nested values can be attributes of elements, or values for attributes (for additional examples, see the Sample Explorer):

    <!-- "Content" is an attribute of the UI element. -->
    <Content>
      
      <!-- "ColorFill" is an element and an attribute of "Content". -->
      <ColorFill Content="Firebrick">
        
        <!-- "Children" is an attribute of "ColorFill". -->
        <Children>
          
          <!-- "Text" is an element and an attribute of "Children". -->
          <Text Content="Content is an attribute of the Text element, which is an attribute of Children" 
                Font ="Arial,12" Color="White" />
          
        </Children>
      </ColorFill>
    </Content>

All attributes can be specified using expanded form, and certain attributes can use an inline form if one has been defined for it. For example, the Font element has both expanded and inline syntax definitions. So when an attribute takes another element as a value, you can pass in the inline syntax if it has been defined. We recommend using inline syntax whenever possible. Otherwise, use expanded form or pass in a reference to an object that has been defined elsewhere. The following example shows these variations.

Inline form:

<Text Content="Inline form 1" Font="Arial,14" />

Inline form, variation:

<Text Content="Inline form 2" Font="Verdana,14,Italic" />

Reference to a font defined in the UI Properties:

<Properties >
    <Font Name="SampleFont" FontName="Verdana" FontSize="14" FontStyle="None" />
</Properties >
. . . 
<Text Content="Inline reference" Font="[SampleFont]" />

Expanded form:

<Text Content="Expanded form" >
    <Color>
        <Color A="255" R="255" G="255" B="225" />
    </Color>
    <Font>
        <Font Font="Arial,12" />
    </Font>
</Text>

The following are the rules of syntax for MCML:

  • Element names, attribute names, and values are case-sensitive.
  • Markup libraries are not global. Namespaces are available to avoid name collisions. Libraries are per-MCML resource, so namespaced library access is required.
  • All types, including CLR and markup types, must be prefixed (except for built-in types such as xmlns). For example: <cor:String … >, <ctl:Button …>, <font://comm:MainFont>.
  • Indirection is indicated by brackets [], and requires a name to reference.
  • All named top-level tags can only be referenced by their given name rather than a namespace.

Note   When using Visual Studio 2008 to develop MCML documents, be aware that the IntelliSense feature does not provide all possible options in the completion list. Rather, it provides syntax options based on best practices and commonly-used scenarios. So, you can use elements and attributes that are not listed and Visual Studio will underline them with wavy colored lines, but the MCML code may still be valid.

  • You cannot index by a variable, property, or other object path. Only literal strings are supported. So, index by using a constant (for example, "abc.#xyz").

Sample Explorer

  • Fundamentals > XML Syntax

See Also