Monday, January 21, 2008

Element content in Glimmerized XML

Now that we have basic namespace support in the Glimmerized XML syntax, let's tackle the next question:

How do we place content in elements?

Here is an example written with basic XML:

<ajax:text>This is an Ajaxified text box</ajax:text>

Here is the same example done with Glimmerized XML:

ajax.text{"This is an Ajaxified text box"}

Intuitive transition, isn't it?

Now, what about mixed content?

Look at this XML snippet:

<p>
  I want to buy these instruments:
  <ul>
    <li>Accordion</li>
    <li>Organ</li>
    <li>Keyboard</li>
  </ul>
  Please make sure they are all Yamaha!
</p>

Here is the same snippet Glimmerized:

p {
  text "I want to buy these instruments:"
  ul {
    li {"Accordion"}
    li {"Organ"}
    li {"Keyboard"}
  }
  "Please make sure they are all Yamaha!"
}

Sweetly simple huh? The "text" prefix is needed to declare content that comes before other elements. Notice how it was left out at the last text snippet. This is because the last line in a Ruby block always represents the return value, so the Glimmer engine took advantage of that fact. This is the same reason why with simple element content, there is no need to utilize the "text" prefix.

The story doesn't end here though. Stay tuned for two upcoming surprises that will make it easier to author mixed content in elements.

No comments: