WML - Formatting

Advertisements


This section will describe basic text formatting elements of WML.

Line Break:

The <br /> element defines a line break and almost all WAP browsers supports a line break tag.

The <br /> element supports the following attributes:

AttributeValueDescription
xml:langlanguage_codeSets the language used in the element
classclass dataSets a class name for the element.
idelement IDA unique ID for the element.

Following is the example showing usage of <br /> element.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Line Break Example">
<p align="center">
This is a <br /> paragraph with a line break.
</p>
</card>

</wml>

This will produce the following result:

WAP Example 4

Text Paragraphs:

The <p> element defines a paragraph of text and WAP browsers always render a paragraph in a new line.

A <p> element is required to define any text, image or a table in WML.

The <p> element supports the following attributes:

AttributeValueDescription
align
  • left
  • right
  • center
This is used to change the horizontal alignment of a paragraph.
mode
  • wrap
  • nowrap
Sets whether a paragraph should wrap lines or not.
xml:langlanguage_codeSets the language used in the element
classclass dataSets a class name for the element.
idelement IDA unique ID for the element.

Following is the example showing usage of <p> element.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Paragraph Example">
<p align="center">
This is first  paragraph
</p>
<p align="right">
This is second  paragraph
</p>
</card>

</wml>

This will produce the following result:

WAP Example 3

WML Tables:

The <table> element along with <tr> and <td> is used to create a table in WML. WML does not allow the nesting of tables

A <table> element should be put with-in <p>...</p> elements.

The <table /> element supports the following attributes:

AttributeValueDescription
columnsnumberSets the number of columns in the table
align
  • L
  • C
  • R
To specify the horizontal text alignment of the columns, you need to assign three letters to the align attribute. Each letter represents the horizontal text alignment of a column. The letter can be L, C, or R. For example, if you want the following settings to be applied to your table:
  • First table column -- Left-aligned

  • Second table column -- Center-aligned

  • Third table column -- Right-aligned

Then you should set the value of the align attribute to LCR.

xml:langlanguage_codeSets the language used in the element
classclass dataSets a class name for the element.
idelement IDA unique ID for the element.

Following is the example showing usage of <table> element.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="WML Tables">
<p>
<table columns="3" align="LCR">
	<tr>
	  <td>Col 1</td>
	  <td>Col 2</td>
	  <td>Col 3</td>
	</tr>

	<tr>
	  <td>A</td>
	  <td>B</td>
	  <td>C</td>
	</tr>

	<tr>
	  <td>D</td>
	  <td>E</td>
	  <td>F</td>
	</tr>
</table>
</p>
</card>

</wml>

This will produce the following result:

WAP Example 5

Preformatted Text:

The <pre> element is used to specify preformatted text in WML. Preformatted text is text of which the format follows the way it is typed in the WML document.

This tag preserves all the white spaces enclosed inside this tag. Make sure you are not putting this tag inside <p>...</p>

The <pre> element supports following attributes:

AttributeValueDescription
xml:langlanguage_codeSets the language used in the element
classclass dataSets a class name for the element.
idelement IDA unique ID for the element.

Following is the example showing usage of <pre> element.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Preformatted Text">
   <pre>
   This is     preformatted
        text and will appear
 as it it.
</pre>
</card>

</wml>

This will produce the following result:

WAP Example 7


Advertisements
Advertisements