XML Namespaces"

From Documentation
m
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
In a ZUML document, a XML namespace is used to identify either a special feature or a component set. We call the former as [[ZUML Reference/ZUML/Namespaces|a standard namespace]], while the later as [[ZUML Reference/ZUML/Languages|a language]].
+
In a ZUML document, an XML namespace is used to identify either a special functionality or a component set. We call the former [[ZUML Reference/ZUML/Namespaces|a standard namespace]] and the latter [[ZUML Reference/ZUML/Languages|a language]].
 +
 
 +
=Standard Namespaces=
 +
For example, the [[ZUML Reference/ZUML/Namespaces/Client|client namespace]] is used to indicate that an XML attribute shall be interpreted as a client-side control.
 +
 
 +
In the following example, <code>w:onFocus</code> is a client-side listener since <code>w:</code> is specified, while <code>onChange</code> is an event attribute of a component.
 +
 
 +
<source lang="xml">
 +
<combobox xmlns:w="client" w:onFocus="this.open()" onChange="doOnChange()"/>
 +
</source>
 +
 
 +
The [[ZUML Reference/ZUML/Namespaces/Native|native namespace]] is another standard namespace used to indicate that an XML element should be generated ''natively'' rather than a component. For example,
 +
 
 +
<source lang="xml">
 +
<n:table xmlns:n="native">
 +
  <n:tr>
 +
    <n:td>Username</n:td>
 +
    <n:td><textbox/></n:td>
 +
  </n:tr>
 +
  <n:tr>
 +
    <n:td>Password</n:td>
 +
    <n:td><textbox type="password"/></n:td>
 +
  </n:tr>
 +
</n:table>
 +
</source>
 +
 
 +
where <code>n:table</code>, <code>n:tr</code> and <code>n:td</code> are native, i.e., they are generated directly to the client without creating a component for each of them.
 +
 
 +
For more information, please refer to [[ZUML Reference/ZUML/Namespaces|ZUML Reference]].
 +
 
 +
=Languages=
 +
A [[ZUML Reference/ZUML/Languages|language]] (<javadoc>org.zkoss.zk.ui.metainfo.LanguageDefinition</javadoc>) is a collection of component definitions. It is also known as a component set.
 +
 
 +
For example, <javadoc>org.zkoss.zul.Window</javadoc>, <javadoc>org.zkoss.zul.Button</javadoc> and <javadoc>org.zkoss.zul.Combobox</javadoc> all belong to the same language called <code>xul/html</code>. It is a ZK variant of XUL (and also known as <code>zul</code>).
 +
 
 +
Component designers are free to designate a component definition to any component sets they prefer, as long as there is no name conflict.
 +
 
 +
When parsing a ZUML document, ZK Loader has to decide the language that an XML element is associated, so that the correct component definition (<javadoc>org.zkoss.zk.ui.metainfo.ComponentDefinition</javadoc>) can be resolved. For example, in the following example, ZK needs to know <code>window</code> belongs to the xul/html language, so its component definition can be retrieved correctly.
 +
 
 +
<source lang="xml">
 +
<window>
 +
</source>
 +
 
 +
ZK Loader first decides the default language from the extension. For example, <code>foo.zul</code> implies the default language is [[ZUML Reference/ZUML/Languages/ZUL|ZUL]].  The default language is used if an XML element is not specified with any XML namespace. For example, <code>window</code> in the previous example will be considered as a component definition of [[ZUML Reference/ZUML/Languages/ZUL|the ZUL langauge]].
 +
 
 +
If the extension is zhtml (such as <code>foo.zhtml</code>), the default language will be [[ZUML Reference/ZUML/Languages/XHTML|XHTML]]. Thus, <code>window</code> in the previous example will be interpreted incorrectly. To solve it, you could specify the XML namespace explicitly as follows.
 +
 
 +
<source lang="xml">
 +
<!-- foo.zhtml -->
 +
<p> <!-- assumed from the XHTML language -->
 +
    <u:window xmlns:u="zul"/> <!-- ZK Loader will search the ZUL language instead -->
 +
</p>
 +
</source>
 +
 
 +
For more information about identifying a language, pelase refer to [[ZUML_Reference/ZUML/Languages#Language_Identification|ZUML Reference]].
  
 
=Version History=
 
=Version History=
{{LastUpdated}}
+
 
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-
| &nbsp;
+
| 5.0.4
| &nbsp;
+
| August, 2010
| &nbsp;
+
| The shortcut was introduced to make it easy to specify a standard namespace, such as native, client and zk.
 +
|-
 +
| 5.0.5
 +
| October, 2010
 +
| The shortcut was introduced to make it easy to specify a component set, such as zul and zhtml.
 
|}
 
|}
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 04:31, 26 January 2024

In a ZUML document, an XML namespace is used to identify either a special functionality or a component set. We call the former a standard namespace and the latter a language.

Standard Namespaces

For example, the client namespace is used to indicate that an XML attribute shall be interpreted as a client-side control.

In the following example, w:onFocus is a client-side listener since w: is specified, while onChange is an event attribute of a component.

<combobox xmlns:w="client" w:onFocus="this.open()" onChange="doOnChange()"/>

The native namespace is another standard namespace used to indicate that an XML element should be generated natively rather than a component. For example,

<n:table xmlns:n="native">
  <n:tr>
    <n:td>Username</n:td>
    <n:td><textbox/></n:td>
  </n:tr>
  <n:tr>
    <n:td>Password</n:td>
    <n:td><textbox type="password"/></n:td>
  </n:tr>
</n:table>

where n:table, n:tr and n:td are native, i.e., they are generated directly to the client without creating a component for each of them.

For more information, please refer to ZUML Reference.

Languages

A language (LanguageDefinition) is a collection of component definitions. It is also known as a component set.

For example, Window, Button and Combobox all belong to the same language called xul/html. It is a ZK variant of XUL (and also known as zul).

Component designers are free to designate a component definition to any component sets they prefer, as long as there is no name conflict.

When parsing a ZUML document, ZK Loader has to decide the language that an XML element is associated, so that the correct component definition (ComponentDefinition) can be resolved. For example, in the following example, ZK needs to know window belongs to the xul/html language, so its component definition can be retrieved correctly.

<window>

ZK Loader first decides the default language from the extension. For example, foo.zul implies the default language is ZUL. The default language is used if an XML element is not specified with any XML namespace. For example, window in the previous example will be considered as a component definition of the ZUL langauge.

If the extension is zhtml (such as foo.zhtml), the default language will be XHTML. Thus, window in the previous example will be interpreted incorrectly. To solve it, you could specify the XML namespace explicitly as follows.

<!-- foo.zhtml -->
<p> <!-- assumed from the XHTML language -->
    <u:window xmlns:u="zul"/> <!-- ZK Loader will search the ZUL language instead -->
</p>

For more information about identifying a language, pelase refer to ZUML Reference.

Version History

Version Date Content
5.0.4 August, 2010 The shortcut was introduced to make it easy to specify a standard namespace, such as native, client and zk.
5.0.5 October, 2010 The shortcut was introduced to make it easy to specify a component set, such as zul and zhtml.



Last Update : 2024/01/26

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.