XML Output"

From Documentation
m ((via JWB))
m (remove empty version history (via JWB))
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
Using ZK to generate XML output is straightforward:
 
Using ZK to generate XML output is straightforward:
  
# Uses the XML component set (<nowiki>http://www.zkoss.org/2007/xml</nowiki> and shortcut is <tt>xml</tt>).
+
# Uses the XML component set (<nowiki>http://www.zkoss.org/2007/xml</nowiki> and shortcut is <code>xml</code>).
 
# Maps the file extension to ZK Loader
 
# Maps the file extension to ZK Loader
 
# Maps the file extension to the XML component set
 
# Maps the file extension to the XML component set
  
The XML component set also provides some special components, such as [[ZK Component Reference/XML Components/Transformer|transformer]] that supports XSTL. Fore more information please refer to [[ZK Component Reference/XML Components|XML Components]].
+
The XML component set also provides some special components, such as [[ZK Component Reference/XML Components/Transformer|transformer]] that supports XSTL. For more information please refer to [[ZK Component Reference/XML Components|XML Components]].
  
 
= Use the XML Component Set =
 
= Use the XML Component Set =
The [[ZUML Reference/ZUML/Languages/XML|XML component set]] (aka., the XML [[ZUML Reference/ZUML/Languages|language]], in ZK terminology) is used to generate XML output. Unlike the [[ZUML Reference/ZUML/Languages/ZUL|ZUL]] or [[ZUML Reference/ZUML/Languages/XHTML|XHTML]] component sets, all unknown<ref>By the unknown tag we mean a XML element that is not associated with a XML namespace, or the namespace is unknown.</ref> tags in a ZUML document are assumed to belong the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]]. It means ZK generates them directly to the output without instantiating a ZK component for each of them.
+
The [[ZUML Reference/ZUML/Languages/XML|XML component set]] (aka., the XML [[ZUML Reference/ZUML/Languages|language]], in ZK terminology) is used to generate XML output. Unlike the [[ZUML Reference/ZUML/Languages/ZUL|ZUL]] or [[ZUML Reference/ZUML/Languages/XHTML|XHTML]] component sets, all unknown<ref>By the unknown tag we mean an XML element that is not associated with an XML namespace, or the namespace is unknown.</ref> tags in a ZUML document are assumed to belong to the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]]. It means ZK generates them directly to the output without instantiating a ZK component for each of them.
  
 
The following is an example that generates the SVG output. It looks very similar to the XML output you want to generate, except you can use zscript, EL expressions, macro components and other ZK features.
 
The following is an example that generates the SVG output. It looks very similar to the XML output you want to generate, except you can use zscript, EL expressions, macro components and other ZK features.
Line 51: Line 51:
 
where
 
where
  
* The content type is specified with the [[ZUML Reference/ZUML/Processing Instructions/page|page directive]]. For SVG, it is <tt>image/svg+xml</tt>. The <tt>xml</tt> processing instruction (<tt><?xml?></tt>) and <tt>DOCTYPE</tt> of the output are also specified in the <tt>page</tt> directive.
+
* The content type is specified with the [[ZUML Reference/ZUML/Processing Instructions/page|page directive]]. For SVG, it is <code>image/svg+xml</code>. The <code>xml</code> processing instruction (<code><?xml?></code>) and <code>DOCTYPE</code> of the output are also specified in the <code>page</code> directive.
* All tags in this example, such as <tt>svg</tt> and <tt>circle</tt>, are associated with a namespace (<nowiki>http://www.w3.org/2000/svg</nowiki>) that is unknown to ZK Loader. Thus, they are assumed to belong the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]]. They are output directly rather than instantiating a ZK component for each of them.
+
* All tags in this example, such as <code>svg</code> and <code>circle</code>, are associated with a namespace (<nowiki>http://www.w3.org/2000/svg</nowiki>) that is unknown to ZK Loader. Thus, they are assumed to belong to the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]]. They are output directly rather than instantiating a ZK component for each of them.
* To use <tt>zscript</tt>, <tt>forEach</tt> and other ZK specific features, you have to specify the [[ZUML Reference/ZUML/Namespaces/ZK|ZK namespace]] (zk).
+
* To use <code>zscript</code>, <code>forEach</code> and other ZK specific features, you have to specify the [[ZUML Reference/ZUML/Namespaces/ZK|ZK namespace]] (zk).
  
 
<blockquote>
 
<blockquote>
Line 61: Line 61:
  
 
= Maps the File Extension to ZK Loader =
 
= Maps the File Extension to ZK Loader =
To let ZK Loader process the file, you have to associate it with the ZK Loader in <tt>WEB-INF/web.xml</tt>. In this example, we map all files with the <tt>.svg</tt> extension to ZK Loader<ref>We assume ZK Loader (<tt>zkLoader</tt>) is mapped to <tt>org.zkoss.zk.ui.http.DHtmlLayoutServlet</tt>.</ref>:
+
To let ZK Loader process the file, you have to associate it with the ZK Loader in <code>WEB-INF/web.xml</code>. In this example, we map all files with the <code>.svg</code> extension to ZK Loader<ref>We assume ZK Loader (<code>zkLoader</code>) is mapped to <code>org.zkoss.zk.ui.http.DHtmlLayoutServlet</code>.</ref>:
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 76: Line 76:
  
 
= Maps the File Extension to the XML Component Set =
 
= Maps the File Extension to the XML Component Set =
Unless the file extension is <tt>.xml</tt>, you have to associate it with the XML component set (aka., the XML language) explicitly in <tt>WEB-INF/zk.xml</tt>. In this example, we map <tt>.svg</tt> to the XML component set:
+
Unless the file extension is <code>.xml</code>, you have to associate it with the XML component set (aka., the XML language) explicitly in <code>WEB-INF/zk.xml</code>. In this example, we map <code>.svg</code> to the XML component set:
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 85: Line 85:
 
</source>
 
</source>
 
   
 
   
where <tt>xml</tt> is the language name of the [[ZUML Reference/ZUML/Languages/XML|XML component set]]. Thus, when ZK Loader parses a file with the <tt>.svg</tt> extension, it knows the default language is the XML component set<ref>For more information about language identification, please refer to [[ZUML Reference/ZUML/Languages|ZUML Reference]].</ref>.
+
where <code>xml</code> is the language name of the [[ZUML Reference/ZUML/Languages/XML|XML component set]]. Thus, when ZK Loader parses a file with the <code>.svg</code> extension, it knows the default language is the XML component set<ref>For more information about language identification, please refer to [[ZUML Reference/ZUML/Languages|ZUML Reference]].</ref>.
  
 
<blockquote>
 
<blockquote>
Line 92: Line 92:
 
</blockquote>
 
</blockquote>
  
=Version History=
+
 
{{LastUpdated}}
 
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 05:55, 6 February 2024

In addition to generating HTML output to a browser, ZK could be used to generate (static) XML output to any client that recognizes it, such as RSS and Web Services.

Using ZK to generate XML output is straightforward:

  1. Uses the XML component set (http://www.zkoss.org/2007/xml and shortcut is xml).
  2. Maps the file extension to ZK Loader
  3. Maps the file extension to the XML component set

The XML component set also provides some special components, such as transformer that supports XSTL. For more information please refer to XML Components.

Use the XML Component Set

The XML component set (aka., the XML language, in ZK terminology) is used to generate XML output. Unlike the ZUL or XHTML component sets, all unknown[1] tags in a ZUML document are assumed to belong to the native namespace. It means ZK generates them directly to the output without instantiating a ZK component for each of them.

The following is an example that generates the SVG output. It looks very similar to the XML output you want to generate, except you can use zscript, EL expressions, macro components and other ZK features.

XML SVG.png

 <?page contentType="image/svg+xml;charset=UTF-8"?>
 <svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg"
 xmlns:z="zk">
     <z:zscript><![CDATA[
     String[] bgnds = {"purple", "blue", "yellow"};
     int[] rads = {30, 25, 20};
     ]]></z:zscript>
     <circle style="fill:${each}" z:forEach="${bgnds}"
         cx="${50+rads[forEachStatus.index]}"
         cy="${20+rads[forEachStatus.index]}"
         r="${rads[forEachStatus.index]}"/>
 </svg>

The generated output will be

<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"
	version="1.1">
	<circle style="fill:purple" cx="80" cy="50" r="30">
	</circle>
	<circle style="fill:blue" cx="75" cy="45" r="25">
	</circle>
	<circle style="fill:yellow" cx="70" cy="40" r="20">
	</circle>
</svg>

where

  • The content type is specified with the page directive. For SVG, it is image/svg+xml. The xml processing instruction (<?xml?>) and DOCTYPE of the output are also specified in the page directive.
  • All tags in this example, such as svg and circle, are associated with a namespace (http://www.w3.org/2000/svg) that is unknown to ZK Loader. Thus, they are assumed to belong to the native namespace. They are output directly rather than instantiating a ZK component for each of them.
  • To use zscript, forEach and other ZK specific features, you have to specify the ZK namespace (zk).

  1. By the unknown tag we mean an XML element that is not associated with an XML namespace, or the namespace is unknown.

Maps the File Extension to ZK Loader

To let ZK Loader process the file, you have to associate it with the ZK Loader in WEB-INF/web.xml. In this example, we map all files with the .svg extension to ZK Loader[1]:

 <servlet-mapping>
     <servlet-name>zkLoader</servlet-name>
     <url-pattern>*.svg</url-pattern>
 </servlet-mapping>

  1. We assume ZK Loader (zkLoader) is mapped to org.zkoss.zk.ui.http.DHtmlLayoutServlet.

Maps the File Extension to the XML Component Set

Unless the file extension is .xml, you have to associate it with the XML component set (aka., the XML language) explicitly in WEB-INF/zk.xml. In this example, we map .svg to the XML component set:

 <language-mapping>
     <language-name>xml</language-name>
     <extension>svg</extension>
 </language-mapping>

where xml is the language name of the XML component set. Thus, when ZK Loader parses a file with the .svg extension, it knows the default language is the XML component set[1].


  1. For more information about language identification, please refer to ZUML Reference.




Last Update : 2024/02/06

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