<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.feedsky.com/styles/feedsky0.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.feedsky.com/sdlyi" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/sdlyi" type="application/rss+xml"></fs:self_link><lastBuildDate>Wed, 24 Jan 2007 14:33:10 GMT</lastBuildDate><title>sdlyi的博客dfgfdgdfgd</title><description>fdgdfg</description><image><url>dfgdfgd</url><title>sdlyi的博客dfgfdgdfgd</title><link>http://sdlyi.bokee.com/index.html</link></image><link>http://sdlyi.bokee.com/index.html</link><admin:generatorAgent rdf:resource="http://blog.bokee.com.com"></admin:generatorAgent><pubDate>Sun, 28 Jan 2007 12:09:41 GMT</pubDate><dc:creator>sdlyi@126.com</dc:creator><item><title>test feedburner</title><link>http://sdlyi.bokee.com/6064648.html</link><description>dsfsadfsdfsdf&amp;amp;nbsp;汉字节&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;788787687686786788 &lt;br /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893375/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893375/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 24 Jan 2007 22:33:10 +0800</pubDate><guid isPermaLink="false">6064648@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/6064648.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893375/1235476</fs:itemid></item><item><title>test2</title><link>http://sdlyi.bokee.com/5949424.html</link><description>fsdfsdfsdfsdfsdfsdfsdfsdfsdffsdf&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893376/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893376/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 12 Dec 2006 22:04:21 +0800</pubDate><guid isPermaLink="false">5949424@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/5949424.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893376/1235476</fs:itemid></item><item><title>test</title><link>http://sdlyi.bokee.com/5948839.html</link><description>sdfdsfsdfsdfsdf&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893377/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893377/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 12 Dec 2006 19:16:13 +0800</pubDate><guid isPermaLink="false">5948839@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/5948839.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893377/1235476</fs:itemid></item><item><title>测试PING BOOSO</title><link>http://sdlyi.bokee.com/5402609.html</link><description>&lt;p align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;&lt;b style=&quot;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 22pt; color: black;&quot;&gt;AF&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 22pt; font-family: 宋体; color: black;&quot;&gt;-&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 22pt; font-family: 宋体; color: black;&quot;&gt;Ⅲ双网络报警控制器&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 14pt; font-family: 宋体; color: black;&quot;&gt;简介&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 21pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: 宋体; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; color: black;&quot;&gt;随着我国经济的高速发展，人民生活水平的不断提高，公共及个人财产不断增加，对于安防报警系统得需求力度也不断加大。为此，我公司自主研发了基于&lt;span lang=&quot;EN-US&quot;&gt;GSM&lt;/span&gt;网络平台和电话传输平台的自动报警系统，本系统结合世界上多种先进报警系统得优点，采用了国际先进的微处理技术、传感技术等，形成了一套针对室内场所防盗、求助、燃气泄漏及烟雾火灾等险情报警系统。本系统突出的优点是结合无线、有线两种告警传输方式，直观、可靠的将报警地点的情况反映到当地的&lt;span lang=&quot;EN-US&quot;&gt;110&lt;/span&gt;指挥中心的系统操作平台和用户手机屏幕上，接警中心据此可在最短时间内立即通知就近警员前往报警地点处理警情。&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 21pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: 宋体; color: black;&quot;&gt;AF-&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; color: black;&quot;&gt;Ⅲ双网络报警控制器集政府机关、办公室、商店、家庭安全、紧急呼救等智能家居为一体，真正实现了超远距离方便、灵活的智能无线报警，成功解决了固定电话和无线短信为一体的高安全、高性能的新一代报警系统。&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 21pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: 宋体; color: black;&quot;&gt;AF-&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; color: black;&quot;&gt;Ⅲ双网络报警控制器可广泛应用于公安、市政、小区物业、银行、电信、医疗、电力、交通、石油、煤炭、铁道、国防等部门行业的安防设备、数据检测以及远程监控。该系统是新一代高质量、高性能的职能报警系统。&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 21pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: 宋体; color: black;&quot;&gt;AF-&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; color: black;&quot;&gt;Ⅲ双网络报警控制器已通过国家&lt;st1:chmetcnv unitname=&quot;C&quot; sourcevalue=&quot;3&quot; hasspace=&quot;False&quot; negative=&quot;False&quot; numbertype=&quot;1&quot; tcsc=&quot;0&quot; w:st=&quot;on&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;3C&lt;/span&gt;&lt;/st1:chmetcnv&gt;认证，并且有中国人保财险每户&lt;span lang=&quot;EN-US&quot;&gt;20&lt;/span&gt;万元的保险。确保发生警情后的损失尽量减少到最低。&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;&lt;a href=&quot;http://publishblog.blogchina.com/blog/tb.b?diaryID=5367690&quot;&gt;test Trackback &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893378/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893378/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 18 Jul 2006 02:37:26 +0800</pubDate><guid isPermaLink="false">5402609@http://sdlyi.bokee.com/</guid><dc:subject>测试</dc:subject><fs:srclink>http://sdlyi.bokee.com/5402609.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893378/1235476</fs:itemid></item><item><title>samba conf</title><link>http://sdlyi.bokee.com/5367690.html</link><description>&lt;h1 id=&quot;title&quot;&gt;&lt;a title=&quot;点击对这个标题进行全文检索&quot; href=&quot;http://suijf/suijf/suijf/samba_conf?action=fullsearch&amp;amp;value=linkto%3A%22samba+conf%22&amp;amp;context=180&quot;&gt;samba conf&lt;/a&gt;&lt;/h1&gt;


&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-9ae297bbf2319ae211b0dacce7d0e9d701078c8b&quot;&gt;SAMBA安装配置&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-59d923e9a7a4da5344a383afff7fb4df40b29fbb&quot;&gt;软件下载&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-b71b20f8dd0854d16a92162eb47866bba5178b78&quot;&gt;安装流程&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-9d7603ede67fd16f46aad2240fe5fed0cbf99938&quot;&gt;配置启动&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-96ccf9d4efca26c63ddd4a40e47aee542961a8cf&quot;&gt;修改配置文件./lib/smb.conf&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-bbb1f488f8678dd8c8de62f0e01e7784bd1605c2&quot;&gt;创建帐户&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-d8e8111db70e019be86ddd532d36ff4a6b7c26d9&quot;&gt;启动SAMBA&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-d556a3e4746de91a6f50ff3b248f95901bcc60e9&quot;&gt;测试启动&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/samba_conf#head-7419e8e4ec4536c725e639fc4179530321164d77&quot;&gt;远程连接&lt;/a&gt;
&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt; &lt;/p&gt;&lt;div lang=&quot;zh&quot; id=&quot;Include_CPUGnav&quot; dir=&quot;ltr&quot;&gt;



&lt;/div&gt;
 

&lt;h3 id=&quot;head-9ae297bbf2319ae211b0dacce7d0e9d701078c8b&quot;&gt;1. SAMBA安装配置&lt;/h3&gt;


&lt;h4 id=&quot;head-59d923e9a7a4da5344a383afff7fb4df40b29fbb&quot;&gt;1.1. 软件下载&lt;/h4&gt;

&lt;ul&gt;&lt;li&gt;&lt;p&gt; &lt;a class=&quot;external&quot; href=&quot;http://samba.org/samba/&quot;&gt;&lt;img width=&quot;11&quot; height=&quot;11&quot; src=&quot;http://suijf/wiki/modern/img/moin-www.png&quot; alt=&quot;[WWW]&quot; /&gt; samba下载地址&lt;/a&gt; &lt;/p&gt;
&lt;/li&gt;&lt;/ul&gt;

&lt;h4 id=&quot;head-b71b20f8dd0854d16a92162eb47866bba5178b78&quot;&gt;1.2. 安装流程&lt;/h4&gt;


&lt;pre&gt;tar xzvf samba-3.0.22.tar.gz&lt;br /&gt;cd samba-3.0.22&lt;br /&gt;cd source/&lt;br /&gt;./autogen.sh&lt;br /&gt;./configure&lt;br /&gt;make;make install&lt;br /&gt;cd ../packaging/&lt;br /&gt;cp -r . /usr/local/samba/&lt;br /&gt;cd /usr/local/samba/setup&lt;br /&gt;cp smb.conf ../lib/&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-9d7603ede67fd16f46aad2240fe5fed0cbf99938&quot;&gt;1.3. 配置启动&lt;/h4&gt;


&lt;h5 id=&quot;head-96ccf9d4efca26c63ddd4a40e47aee542961a8cf&quot;&gt;1.3.1. 修改配置文件./lib/smb.conf&lt;/h5&gt;


&lt;pre&gt;[smb]&lt;br /&gt;   comment = Mary's and Fred's stuff&lt;br /&gt;   path = /opt&lt;br /&gt;   valid users = root admin&lt;br /&gt;   public = yes&lt;br /&gt;   writable = yes&lt;br /&gt;   printable = no&lt;br /&gt;   create mask = 0765&lt;br /&gt;&lt;/pre&gt;

&lt;h5 id=&quot;head-bbb1f488f8678dd8c8de62f0e01e7784bd1605c2&quot;&gt;1.3.2. 创建帐户&lt;/h5&gt;


&lt;pre&gt;useradd admin&lt;br /&gt;passwd admin&lt;br /&gt;smbpasswd  -a admin&lt;br /&gt;&lt;/pre&gt;

&lt;h5 id=&quot;head-d8e8111db70e019be86ddd532d36ff4a6b7c26d9&quot;&gt;1.3.3. 启动SAMBA&lt;/h5&gt;


&lt;pre&gt;/usr/local/samba/sbin/smbd -D&lt;br /&gt;/usr/local/samba/sbin/nmbd -D&lt;br /&gt;&lt;/pre&gt;

&lt;h5 id=&quot;head-d556a3e4746de91a6f50ff3b248f95901bcc60e9&quot;&gt;1.3.4. 测试启动&lt;/h5&gt;


&lt;pre&gt;shell#smbclient -U% -L localhost&lt;br /&gt;params.c:OpenConfFile() - Unable to open configuration file &amp;amp;quot;/usr/local/lib/smb.conf&amp;amp;quot;:&lt;br /&gt;        No such file or directory&lt;br /&gt;smbclient: Can't load /usr/local/lib/smb.conf - run testparm to debug it&lt;br /&gt;Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.22]&lt;br /&gt;&lt;br /&gt;        Sharename       Type      Comment&lt;br /&gt;        ---------       ----      -------&lt;br /&gt;        IPC$            IPC       IPC Service (Samba Server)&lt;br /&gt;        smb             Disk      Mary's and Fred's stuff&lt;br /&gt;        ADMIN$          IPC       IPC Service (Samba Server)&lt;br /&gt;Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.22]&lt;br /&gt;&lt;br /&gt;        Server               Comment&lt;br /&gt;        ---------            -------&lt;br /&gt;        LOCALHOST            Samba Server&lt;br /&gt;&lt;br /&gt;        Workgroup            Master&lt;br /&gt;        ---------            -------&lt;br /&gt;        BOKEE-INC            SPS&lt;br /&gt;        CHINALABS            LAB1&lt;br /&gt;        CONTACTUS            MAIL&lt;br /&gt;        HOME                 WINIX&lt;br /&gt;        MYGROUP              LOCALHOST&lt;br /&gt;&lt;/pre&gt;

&lt;h5 id=&quot;head-7419e8e4ec4536c725e639fc4179530321164d77&quot;&gt;1.3.5. 远程连接&lt;/h5&gt;


&lt;pre&gt;smbclient  //192.168.27.25/smb -U admin   //连接成功&lt;br /&gt;&lt;/pre&gt;
&lt;script language=&quot;Javascript&quot; src=&quot;http://www.downes.ca/referrers.js&quot;&gt;&lt;/script&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893379/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893379/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 11 Jul 2006 01:25:13 +0800</pubDate><guid isPermaLink="false">5367690@http://sdlyi.bokee.com/</guid><dc:subject>服务器配置</dc:subject><fs:srclink>http://sdlyi.bokee.com/5367690.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893379/1235476</fs:itemid></item><item><title>apache mod rewrite</title><link>http://sdlyi.bokee.com/5367682.html</link><description>&lt;h1 id=&quot;title&quot;&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite?action=fullsearch&amp;amp;value=linkto%3A%22suijf%2Fapache+mod+rewrite%22&amp;amp;context=180&quot; title=&quot;点击对这个标题进行全文检索&quot;&gt;suijf/apache mod rewrite&lt;/a&gt;&lt;/h1&gt;


&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-a2cc8a76f26ca24e36686efc0c605db5d4925b81&quot;&gt;apache mod_rewirte相关文档&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-348e3a42fc1eb16d51a2a68e8a757a8c3a1e79c6&quot;&gt;安装篇&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-ca229d21fd2fcf8eb75eec2b3cccd2a2c19820e1&quot;&gt;配置篇&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-90de9d5aec1df8c09f733864ad82b0454427f3ce&quot;&gt;首先配置apache的httpd.conf，目的是使.htaccess文件生效&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-f3237442e00cc9029409b94dfe557864716a21df&quot;&gt;在/var/www/bulknews下设置.htaccess文件&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-4d7d3c091cbf8129899aa7c84f87126029f7698b&quot;&gt;一个配置文件&lt;/a&gt;
&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-1f43584dbc8226759a9c8bcebda8bbb15b703afb&quot;&gt;解析配置文件字段&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-0a42ed045dd0f13bb6b617c189e5e684afdf8252&quot;&gt;RewriteEngine 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-d37a3c80e360165c26a6bc455a4bd2359b9ceccb&quot;&gt;RewriteLock 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-782501c6537222cff78b0a711ecde861d72c44f9&quot;&gt;RewriteLog 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-6e44d2b65c08c0e2775862562243cfab098986cb&quot;&gt;RewriteLogLevel 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-05fa0184f2ccfdeec13585f9c06234f43457f90c&quot;&gt;RewriteMap 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-7f61b8bda43fcfc66299e14c35babdcd8cf8b9df&quot;&gt;RewriteOptions 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-e452bd75354740f5a3aa21260e4751958646a6f7&quot;&gt;RewriteRule 指令&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-449067588d70dbb46152a19d2939dadcb2c881c9&quot;&gt;正则表达式的一些用法&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-c1a783abd0c43fc6766477297a5e74ffa65e6394&quot;&gt;flags(要点)&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-e45a30d03374241a9225d35c8f2880f602415f03&quot;&gt;redirect|R [=code]&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-4da6a8cf7b316540ff187bfe0042a4769405a1fa&quot;&gt;forbidden|F&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-d261957dc84b822566ac77130cebd8ade807b95b&quot;&gt;gone|G&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-a380fd30a6ec292b321280d899aedd4f01a33d37&quot;&gt;proxy|P&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-bee8590a2aa7204ee5f493d37802ace024ac96d1&quot;&gt;last|L&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-8d6a91578c3026e49beb23c441e190fc94935242&quot;&gt;chain|C&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-b08d2296e7dc526971f278c5b649299b5b0ce882&quot;&gt;type|T=MIME-type&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-7bbc96d697995edc76d5ca350cb5eb667bb299b6&quot;&gt;nosubreq|NS&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-bbc5a01abf4910f65933c2fb9c5a3bfeaa7c0733&quot;&gt;nocase|NC&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-319fe02bc0df5339a8b4369aff6c606435f9f12a&quot;&gt;noescape|NE&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-3cab16941b26fc4e0ab82265f3a7597f84ba0646&quot;&gt;passthrough|PT&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/UserPreferences/suijf/apache_mod_rewrite#head-023435be676d5c1bbf1fbefcf48c5d8bad31c60c&quot;&gt;cookie|CO=NAME:VAL:domain[:lifetime[:path]]&lt;/a&gt;
&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;/ol&gt;

&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt; &lt;/p&gt;&lt;div lang=&quot;zh&quot; dir=&quot;ltr&quot; id=&quot;Include_CPUGnav&quot;&gt;



&lt;/div&gt;
 

&lt;h2 id=&quot;head-a2cc8a76f26ca24e36686efc0c605db5d4925b81&quot;&gt;1. apache mod_rewirte相关文档&lt;/h2&gt;


&lt;h3 id=&quot;head-348e3a42fc1eb16d51a2a68e8a757a8c3a1e79c6&quot;&gt;1.1. 安装篇&lt;/h3&gt;

&lt;p&gt;编译apache 包含mod_rewrite模块 
&lt;/p&gt;
&lt;pre&gt;./configure --prefix=/usr/local/apache2 --enable-cache --enable-disk-cache --enable-file-cache --enable-so --enable-rewrite=shared --enable-proxy --with-mpm=worker --with-threads=yes&lt;br /&gt;make&lt;br /&gt;make install&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;apache动态编译mod_rewrite模块 
&lt;/p&gt;
&lt;pre&gt;/usr/local/apache2/bin/apxs -ci /usr/local/src/httpd-2.0.52/modules/mappers/mod_rewrite.c&lt;br /&gt;&lt;/pre&gt;

&lt;h3 id=&quot;head-ca229d21fd2fcf8eb75eec2b3cccd2a2c19820e1&quot;&gt;1.2. 配置篇&lt;/h3&gt;

&lt;p&gt;我们的目标是把http://www.bulknews.cn/show.php?id=1014700通过rewrite的url重写，使可以直接http://www.bulknews.cn/1014700.html访问 &lt;/p&gt;

&lt;h4 id=&quot;head-90de9d5aec1df8c09f733864ad82b0454427f3ce&quot;&gt;1.2.1. 首先配置apache的httpd.conf，目的是使.htaccess文件生效&lt;/h4&gt;


&lt;pre&gt;&amp;amp;lt;VirtualHost a.b.c.d&amp;amp;gt;&lt;br /&gt;    ServerAdmin a@b.com&lt;br /&gt;    DocumentRoot /var/www/bulknews&lt;br /&gt;    ServerName www.bulknews.cn&lt;br /&gt;&amp;amp;lt;Directory /&amp;amp;gt;&lt;br /&gt;      Options FollowSymLinks&lt;br /&gt;      AllowOverride All&lt;br /&gt;&amp;amp;lt;/Directory&amp;amp;gt;&lt;br /&gt;ErrorLog  &amp;amp;quot;|/usr/local/sbin/cronolog /var/log/www/wapya/www.bulknews.cn_error_log.%Y%m%d&amp;amp;quot;&lt;br /&gt;CustomLog &amp;amp;quot;|/usr/local/sbin/cronolog /var/log/www/wapya/www.bulknews.cn_access_log.%Y%m%d&amp;amp;quot; combined&lt;br /&gt;&amp;amp;lt;/VirtualHost&amp;amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;注意，这里必须是&lt;a href=&quot;http://suijf/suijf/UserPreferences/FollowSymLinks&quot; class=&quot;nonexistent&quot;&gt;FollowSymLinks&lt;/a&gt;，&lt;a href=&quot;http://suijf/suijf/UserPreferences/AllowOverride&quot; class=&quot;nonexistent&quot;&gt;AllowOverride&lt;/a&gt;是All，否则rewrite引擎根本不起作用，另外如果你的apache默认根目录是/var/www 的话，在/var/www的配置字段也要设置 Options &lt;a href=&quot;http://suijf/suijf/UserPreferences/FollowSymLinks&quot; class=&quot;nonexistent&quot;&gt;FollowSymLinks&lt;/a&gt; &lt;/p&gt;
&lt;ul&gt;&lt;li style=&quot;list-style-type: none;&quot;&gt;&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/AllowOverride&quot; class=&quot;nonexistent&quot;&gt;AllowOverride&lt;/a&gt; All &lt;/p&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;我的就因为这个，只是在虚拟主机设置，导致一直不能实现静态页面的转化。 &lt;/p&gt;

&lt;h4 id=&quot;head-f3237442e00cc9029409b94dfe557864716a21df&quot;&gt;1.2.2. 在/var/www/bulknews下设置.htaccess文件&lt;/h4&gt;


&lt;pre&gt;RewriteEngine   on&lt;br /&gt;RewriteBase     /&lt;br /&gt;RewriteRule     (.+)\.html$ show.php?id=$1 [L]&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;OK，重启web服务，这时候你就可以正常访问http://www.bulknews.cn/1014700.html &lt;/p&gt;

&lt;h4 id=&quot;head-4d7d3c091cbf8129899aa7c84f87126029f7698b&quot;&gt;1.2.3. 一个配置文件&lt;/h4&gt;


&lt;pre&gt;&amp;amp;lt;IfModule mod_rewrite.c&amp;amp;gt;&lt;br /&gt;ProxyVia on&lt;br /&gt;RewriteEngine On&lt;br /&gt;#RewriteCond     %{REQUEST_URI}          ^.*&lt;br /&gt;RewriteCond     %{REQUEST_URI}          ^.*&lt;br /&gt;#RewriteCond     %{HTTP_HOST}           ^[a-zA-Z]+.*\.feeds&lt;br /&gt;#RewriteBase    /&lt;br /&gt;#RewriteRule&lt;br /&gt;#RewriteRule     ^/$            doUser.php?domain=$1&amp;amp;amp;uri=%{REQUEST_URI} [P]&lt;br /&gt;#RewriteRule     ^/([a-z]+)             doUser.php?domain=$1&amp;amp;amp;uri=%{REQUEST_URI} [P,L]&lt;br /&gt;#RewriteRule     ^/user/([a-zA-Z]+)             doUser.php?domain=$1 [R]&lt;br /&gt;RewriteRule     !^/doUser.php$                  - [C]&lt;br /&gt;RewriteRule     ^/([a-zA-Z]+)/?.*$              doUser.php?domain=$1&amp;amp;amp;uri=%{REQUEST_URI} [R,L]&lt;br /&gt;#RewriteRule     ^/([a-zA-Z]+.*$)               doUser.php?domain=$1&amp;amp;amp;uri=%{HTTP_HOST} [R]&lt;br /&gt;#RewriteRule     ^/([a-zA-Z]+./?$)              doUser.php?domain=$1&amp;amp;amp;uri=%{HTTP_HOST} [R]&lt;br /&gt;#RewriteRule     ^/self                   http://localhost:8080/keyLink/showKey.k [P]&lt;br /&gt;#RewriteRule     ^/copy/([0-9]+)          http://localhost:8080/keyLink/copyKey.k?linkID=$1 [P]&lt;br /&gt;#RewriteRule     ^/add                    http://localhost:8080/keyLink/createKey.k [P]&lt;br /&gt;#RewriteRule     ^/link/([0-9]+)          http://localhost:8080/keyLink/showLink.k?linkID=$1 [P]&lt;br /&gt;#RewriteRule     ^/t/WSSE/                http://localhost:8080/t/WSSE/  [P]&lt;br /&gt;#RewriteRule     ^/showTags                http://localhost:8080/homePage.k?method=showTags  [P]&lt;br /&gt;#RewriteRule     ^/shownews/([0-9]+)          http://localhost:8080/homePage.k?method=showNews&amp;amp;amp;newsID=$1  [P]&lt;br /&gt;&lt;br /&gt;#RewriteRule     ^/xml-rpc              http://localhost:8080/xml-rpc [P]&lt;br /&gt;#RewriteRule     ^/index.html           /usr/local/flyer/key/index.html  [L]&lt;br /&gt;#RewriteRule     ^/download.html       /usr/local/flyer/key/download.html  [L]&lt;br /&gt;#RewriteRule     ^/download.html       http://localhost:8080/download.html [P]&lt;br /&gt;&lt;br /&gt;RewriteLogLevel 0&lt;br /&gt;RewriteLog   /usr/local/apache2/logs/rewrite.log&lt;br /&gt;&amp;amp;lt;/IfModule&amp;amp;gt;&lt;br /&gt;&lt;/pre&gt;

&lt;h3 id=&quot;head-1f43584dbc8226759a9c8bcebda8bbb15b703afb&quot;&gt;1.3. 解析配置文件字段&lt;/h3&gt;


&lt;h4 id=&quot;head-0a42ed045dd0f13bb6b617c189e5e684afdf8252&quot;&gt;1.3.1. RewriteEngine 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteEngine&quot; class=&quot;nonexistent&quot;&gt;RewriteEngine&lt;/a&gt;指令打开或关闭运行时刻的重写引擎。 如果设置为off，则mod_rewrite模块不执行任何运行时刻的重写操作， 甚至也不更新SCRIPT_URx环境变量。 &lt;/p&gt;
&lt;p&gt;使用该指令可以使mod_rewrite模块无效，而无须注释所有的&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteRule&quot; class=&quot;nonexistent&quot;&gt;RewriteRule&lt;/a&gt;指令! &lt;/p&gt;
&lt;p&gt;注意：默认情况下，重写配置是不可继承的， 即，必须在每个需要的虚拟主机中设置一个&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteEngine&quot; class=&quot;nonexistent&quot;&gt;RewriteEngine&lt;/a&gt; on指令。 &lt;/p&gt;

&lt;h4 id=&quot;head-d37a3c80e360165c26a6bc455a4bd2359b9ceccb&quot;&gt;1.3.2. RewriteLock 指令&lt;/h4&gt;

&lt;p&gt;此指令设置mod_rewrite为了和&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteMap&quot; class=&quot;nonexistent&quot;&gt;RewriteMap&lt;/a&gt; 程序通讯而使用的一个同步加锁文件的名称。 在需要使用重写映射表程序时，它必须是一个本地路径(而不能是一个NFS挂接设备)； 对其他类型的重写映射表，则无此要求。 &lt;/p&gt;

&lt;h4 id=&quot;head-782501c6537222cff78b0a711ecde861d72c44f9&quot;&gt;1.3.3. RewriteLog 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLog&quot; class=&quot;nonexistent&quot;&gt;RewriteLog&lt;/a&gt;指令设置用于记录所有重写操作的文件的名称。 如果此文件名不是以斜杠('/')开头，则它是相对于Server Root的。 此指令应该仅仅出现在服务器级配置中。 &lt;/p&gt;
&lt;p&gt;如果要关闭对重写操作的记录，不推荐把Filename设置为/dev/null，因为，虽然重写引擎不能输出记录了，但仍会内部地建立这个日志文件， 它会使服务器速度降低，而且对管理员毫无益处! 要关闭日志，可以删除或注解&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLog&quot; class=&quot;nonexistent&quot;&gt;RewriteLog&lt;/a&gt;指令， 或者使用&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLogLevel&quot; class=&quot;nonexistent&quot;&gt;RewriteLogLevel&lt;/a&gt; 0! 安全 参见Apache Security Tips，其中讲述了， 为什么如果存放日志的目录对除了启动服务器以外的用户是可写的会带来安全隐患。 举例 &lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLog&quot; class=&quot;nonexistent&quot;&gt;RewriteLog&lt;/a&gt; &amp;amp;quot;/usr/local/var/apache/logs/rewrite.log&amp;amp;quot; &lt;/p&gt;

&lt;h4 id=&quot;head-6e44d2b65c08c0e2775862562243cfab098986cb&quot;&gt;1.3.4. RewriteLogLevel 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLogLevel&quot; class=&quot;nonexistent&quot;&gt;RewriteLogLevel&lt;/a&gt;指令设置重写引擎日志的详细程度的级别。 默认级别0意味着不记录，而9或更大的值意味着记录所有的操作。 &lt;/p&gt;
&lt;p&gt;要关闭重写引擎日志，可以简单地设此值为0，关闭所有的重写操作记录。 &lt;/p&gt;
&lt;p&gt;使用较高的Level值会使Apache服务器速度急剧下降! 重写日志使用大于2的Level值只用于调试! 举例 &lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLogLevel&quot; class=&quot;nonexistent&quot;&gt;RewriteLogLevel&lt;/a&gt; 3 &lt;/p&gt;

&lt;h4 id=&quot;head-05fa0184f2ccfdeec13585f9c06234f43457f90c&quot;&gt;1.3.5. RewriteMap 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteMap&quot; class=&quot;nonexistent&quot;&gt;RewriteMap&lt;/a&gt;定义一个映射表， 由映射函数用于查找关键词来插入/替换字段。此查找操作的源可以是多种类型。 &lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/MapName&quot; class=&quot;nonexistent&quot;&gt;MapName&lt;/a&gt;是映射表的名称， 指定了一个映射函数，用于重写规则的字符串替换，它可以是下列形式之一： 
&lt;/p&gt;
&lt;pre&gt;${ MapName : LookupKey }&lt;br /&gt;${ MapName : LookupKey | DefaultValue }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;如果使用了这样的形式，则会在&lt;a href=&quot;http://suijf/suijf/UserPreferences/MapName&quot; class=&quot;nonexistent&quot;&gt;MapName&lt;/a&gt;中查找关键词&lt;a href=&quot;http://suijf/suijf/UserPreferences/LookupKey&quot; class=&quot;nonexistent&quot;&gt;LookupKey&lt;/a&gt;。 如果找到了，则被替换成&lt;a href=&quot;http://suijf/suijf/UserPreferences/SubstValue&quot; class=&quot;nonexistent&quot;&gt;SubstValue&lt;/a&gt;； 如果没有找到，则被替换成&lt;a href=&quot;http://suijf/suijf/UserPreferences/DefaultValue&quot; class=&quot;nonexistent&quot;&gt;DefaultValue&lt;/a&gt;， 如果没有指定&lt;a href=&quot;http://suijf/suijf/UserPreferences/DefaultValue&quot; class=&quot;nonexistent&quot;&gt;DefaultValue&lt;/a&gt;，则被替换成空字符串。 &lt;/p&gt;
&lt;p&gt;可以使用下列&lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;和&lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;的组合: &lt;/p&gt;
&lt;p&gt;标准纯文本 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;: txt, &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;: 有效的Unix文件系统文件名 这是重写映射表的标准形式，即， &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;是一个纯文本文件，包含空行、注释行(以字符'#'打头)， 以及每行一个的替换对，如下。 
&lt;/p&gt;
&lt;pre&gt;MatchingKey SubstValue&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;##&lt;br /&gt;## map.txt -- rewriting map&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;Ralf.S.Engelschall rse # Bastard Operator From Hell&lt;br /&gt;Mr.Joe.Average joe # Mr. Average&lt;br /&gt;&lt;br /&gt;RewriteMap real-to-user txt:/path/to/file/map.txt&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;随机纯文本 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;: rnd, &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;: 有效的Unix文件系统文件名 这个与上述的标准纯文本很相似，但它有一个特殊的后处理特性： 查找完毕后，会解析其中包含的含义为or&lt;em&gt;和|&lt;/em&gt;符号。也就是说，会随机地选择其中之一作为实际的返回值。 虽然这看似毫无意义，但它的设计意图是，在一个查找值是服务器名称的反向代理环境中，实现负载平衡。如： 
&lt;/p&gt;
&lt;pre&gt;##&lt;br /&gt;## map.txt -- rewriting map&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;static www1|www2|www3|www4&lt;br /&gt;dynamic www5|www6&lt;br /&gt;&lt;br /&gt;RewriteMap servers rnd:/path/to/file/map.txt&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;散列文件 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;: dbm[=type], &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;:
有效的Unix文件系统文件名 这里的源是一个二进制格式的DBM文件，包含了与纯文本相同的内容，
但是因为它有优化的特殊表现形式，使它的查找速度明显快得多。此类型可以是sdbm, gdbm, ndbm或db，由compile-time
settings所决定。如果省略type，则使用编译时选择的缺省设置。你可以使用任何DBM工具或者下列Perl脚本来建立这个文件，但必须保证
DBM的类型正确。 建立NDBM文件的例子： &lt;/p&gt;
&lt;pre&gt;#!/path/to/bin/perl&lt;br /&gt;##&lt;br /&gt;## txt2dbm -- convert txt map to dbm format&lt;br /&gt;##&lt;br /&gt;&lt;br /&gt;use NDBM_File;&lt;br /&gt;use Fcntl;&lt;br /&gt;&lt;br /&gt;($txtmap, $dbmmap) = @ARGV;&lt;br /&gt;&lt;br /&gt;open(TXT, &amp;amp;quot;&amp;amp;lt;$txtmap&amp;amp;quot;) or die &amp;amp;quot;Couldn't open $txtmap!\n&amp;amp;quot;;&lt;br /&gt;tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)&lt;br /&gt;or die &amp;amp;quot;Couldn't create $dbmmap!\n&amp;amp;quot;;&lt;br /&gt;&lt;br /&gt;while (&amp;amp;lt;TXT&amp;amp;gt;) {&lt;br /&gt;next if (/^\s*#/ or /^\s*$/);&lt;br /&gt;$DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;untie %DB;&lt;br /&gt;close(TXT);&lt;br /&gt;&lt;br /&gt;$ txt2dbm map.txt map.db&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;内部函数 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;: int, &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;: 内部的Apache函数 这里的源是一个内部的Apache函数。 目前，还不能由你自己建立，只能使用下列已经存在的函数： &lt;/p&gt;
&lt;p&gt;toupper: 转换查找关键词为大写. tolower: 转换查找关键词为小写. escape: 转换查找关键词中的特殊字符为十六进制编码. unescape: 转换查找关键词中的十六进制编码为特殊字符. 外部的重写程序 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapType&quot; class=&quot;nonexistent&quot;&gt;MapType&lt;/a&gt;: prg, &lt;a href=&quot;http://suijf/suijf/UserPreferences/MapSource&quot; class=&quot;nonexistent&quot;&gt;MapSource&lt;/a&gt;: 有效的Unix文件系统文件名 这里的源是一个程序，而不是一个映射表文件。 程序的编制语言可以随意选择，但最终结果必须是可执行的 (即, 或者是目标代码，或者是首行为'#!/path/to/interpreter'的脚本). &lt;/p&gt;
&lt;p&gt;此程序仅在Apache服务器启动时启动一次， 随后通过stdin和stdout文件句柄与重写引擎交互。对每个映射函数的查找操作，它从stdin接收以回车结束的查找关键词， 然后把查找结果以回车结束反馈到stdout，如果查找失败，则返回四个字符的NULL&lt;em&gt; (即, 对给定的关键词没有对应的值)。 此程序的最简单形式是一个1:1的映射(即,key == value)，如: 
&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;#!/usr/bin/perl&lt;br /&gt;$| = 1;&lt;br /&gt;while (&amp;amp;lt;STDIN&amp;amp;gt;) {&lt;br /&gt;# ...put here any transformations or lookups...&lt;br /&gt;print $_;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;但是必须注意: &lt;/p&gt;
&lt;p&gt;即使它看来简单而愚蠢，只要正确，就保持原样(Keep it simple, stupid) (KISS),
因为，在规则起作用时，此程序的崩溃会直接导致Apache服务器的崩溃。 避免犯一个常见的错误: 绝不要对stdout做缓冲I/O!
它会导致死循环! 所以上述例子中才会有$|=1&lt;em&gt;... 使用&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteLock&quot; class=&quot;nonexistent&quot;&gt;RewriteLock&lt;/a&gt;指令定义一个加锁文件， 用于同步mod_rewrite和此程序之间的通讯。缺省时是没有同步操作的。 &lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteMap&quot; class=&quot;nonexistent&quot;&gt;RewriteMap&lt;/a&gt;指令允许多次出现。 对每个映射函数都可以使用一个&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteMap&quot; class=&quot;nonexistent&quot;&gt;RewriteMap&lt;/a&gt;指令来定义其重写映射表。 虽然不能在目录的上下文中定义映射表， 但是，完全可以在其中使用映射表。 &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;注意 对于纯文本和DBM格式的文件，已经查找过的关键词会被缓存在内核中， 直到映射表的mtime改变了或者服务器重启了。 这样，你可以把每个请求都会用到的映射函数放在规则中，这是没有问题的，因为外部查找只进行一次! &lt;/p&gt;

&lt;h4 id=&quot;head-7f61b8bda43fcfc66299e14c35babdcd8cf8b9df&quot;&gt;1.3.6. RewriteOptions 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteOptions&quot; class=&quot;nonexistent&quot;&gt;RewriteOptions&lt;/a&gt;指令为当前服务器级和目录级的配置设置一些选项。 Option可以是下列值之一： &lt;/p&gt;
&lt;p&gt;inherit 此值强制当前配置可以继承其父配置。 在虚拟主机级配置中，它意味着主服务器的映射表、条件和规则可以被继承。 在目录级配置中，它意味着其父目录的.htaccess中的条件和规则可以被继承。 &lt;a href=&quot;http://suijf/suijf/UserPreferences/MaxRedirects&quot; class=&quot;nonexistent&quot;&gt;MaxRedirects&lt;/a&gt;=number 为了避免目录级&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteRule&quot; class=&quot;nonexistent&quot;&gt;RewriteRule&lt;/a&gt;的无休止的内部重定向， 在此类重定向和500内部服务器错误次数达到一个最大值的时候， mod_rewrite会停止对此请求的处理。 如果你确实需要对每个请求允许大于10次的内部重定向，可以增大这个值。 &lt;/p&gt;

&lt;h4 id=&quot;head-e452bd75354740f5a3aa21260e4751958646a6f7&quot;&gt;1.3.7. RewriteRule 指令&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteRule&quot; class=&quot;nonexistent&quot;&gt;RewriteRule&lt;/a&gt;指令是重写引擎的根本。此指令可以多次使用。 每个指令定义一个简单的重写规则。这些规则的定义顺序尤为重要, 因为，在运行时刻，规则是按这个顺序逐一生效的. &lt;/p&gt;
&lt;p&gt;Pattern是一个作用于当前URL的兼容perl的正则表达式. 这里的当前是指该规则生效时的URL的值。 它可能与被请求的URL不同，因为其他规则可能在此之前已经发生匹配并对它做了改动。  &lt;/p&gt;

&lt;h4 id=&quot;head-449067588d70dbb46152a19d2939dadcb2c881c9&quot;&gt;1.3.8. 正则表达式的一些用法&lt;/h4&gt;


&lt;pre&gt;Text:&lt;br /&gt;. Any single character&lt;br /&gt;[chars] Character class: One of chars&lt;br /&gt;[^chars] Character class: None of chars&lt;br /&gt;text1|text2 Alternative: text1 or text2&lt;br /&gt;&lt;br /&gt;Quantifiers:&lt;br /&gt;? 0 or 1 of the preceding text&lt;br /&gt;* 0 or N of the preceding text (N &amp;amp;gt; 0)&lt;br /&gt;+ 1 or N of the preceding text (N &amp;amp;gt; 1)&lt;br /&gt;&lt;br /&gt;Grouping:&lt;br /&gt;(text) Grouping of text&lt;br /&gt;(either to set the borders of an alternative or&lt;br /&gt;for making backreferences where the Nth group can&lt;br /&gt;be used on the RHS of a RewriteRule with $N)&lt;br /&gt;&lt;br /&gt;Anchors:&lt;br /&gt;^ Start of line anchor&lt;br /&gt;$ End of line anchor&lt;br /&gt;&lt;br /&gt;Escaping:&lt;br /&gt;\char escape that particular char&lt;br /&gt;(for instance to specify the chars &amp;amp;quot;.[]()&amp;amp;quot; etc.)&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;更多有关正则表达式的资料请参见perl正则表达式手册页(&amp;amp;quot;perldoc perlre&amp;amp;quot;). 如果你对正则表达式的更详细的资料及其变种(POSIX regex 等.)感兴趣， 请参见以下专著: &lt;/p&gt;
&lt;p&gt;Mastering Regular Expressions Jeffrey E.F. Friedl Nutshell Handbook
Series O'Reilly &amp;amp;amp; Associates, Inc. 1997 ISBN 1-56592-257-3 &lt;/p&gt;
&lt;p&gt;另外，在mod_rewrite中，还可以使用否字符('!')的pattern前缀，以实现pattern的反转。 比如：如果当前URL不与pattern相匹配&lt;em&gt;. 它用于使用否pattern较容易描述的需要排除的某些情况，或者作为最后一条规则。 &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;注意 使用否字符以反转pattern时，pattern中不能使用分组的通配成分。
由于pattern不匹配而使分组的内容是空的，所以它是不可能实现的。 因此，如果使用了否pattern，那么后继的字符串中就不能使用$N!
重写规则中的Substitution是， 当原始URL与Pattern相匹配时，用以替代(或替换)的字符串。 除了纯文本，还可以使用 &lt;/p&gt;
&lt;p&gt;$N 反向引用&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteRule&quot; class=&quot;nonexistent&quot;&gt;RewriteRule&lt;/a&gt;的pattern %N 反向引用最后匹配的&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteCond&quot; class=&quot;nonexistent&quot;&gt;RewriteCond&lt;/a&gt; pattern 规则条件测试字符串中(%{VARNAME})的服务器变量 映射函数调用(${mapname:key|default}) 反向引用的$N (N=0..9) 是指用Pattern所匹配的第N组的内容去替换URL。服务器变量与&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteCond&quot; class=&quot;nonexistent&quot;&gt;RewriteCond&lt;/a&gt;指令的&lt;a href=&quot;http://suijf/suijf/UserPreferences/TestString&quot; class=&quot;nonexistent&quot;&gt;TestString&lt;/a&gt;相同。 映射函数由&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteMap&quot; class=&quot;nonexistent&quot;&gt;RewriteMap&lt;/a&gt;指令所决定，其说明也参见该指令。这三种类型变量按上面列表中的顺序被扩展。 &lt;/p&gt;
&lt;p&gt;如上所述，所有的重写规则都是(按配置文件中的定义顺序)作用于Substitution的。 URL被Substitution完全地替换，并继续处理直到所有规则处理完毕， 除非用L标记显式地终结 - 见下文。 &lt;/p&gt;
&lt;p&gt;'-'是一个特殊的替换串，意思是不要替换! 似乎很愚蠢吧? 不, 它可以用于仅仅匹配某些URL而无须替换的情况下，即， 在发生替换前，允许以C (chain)标记连接的多个pattern同时起作用。 &lt;/p&gt;
&lt;p&gt;还有，你甚至可以在替换字符串中新建包含请求串的URL。 在替换串中使用问号，以标明其后继的成分应该被重新注入到QUERY_STRING中。 要删除一个已有的请求串，可以用问号来终结替换字符串。 &lt;/p&gt;
&lt;p&gt;注意 一个特殊功能: 在用[url]&lt;a href=&quot;http://thishost%5b/url%5D%5B:thisport%5D%E4%BD%9C%E4%B8%BA%E6%9B%BF%E6%8D%A2%E5%AD%97%E6%AE%B5%E7%9A%84%E5%89%8D%E7%BC%80%E6%97%B6%EF%BC%8C&quot;&gt;&lt;img width=&quot;11&quot; height=&quot;11&quot; alt=&quot;[WWW]&quot; src=&quot;http://suijf/wiki/modern/img/moin-www.png&quot; /&gt; http://thishost[/url][:thisport]作为替换字段的前缀时，&lt;/a&gt; mod_rewrite会把它自动剥离出去。 在配合生成主机名的映射函数使用的时候，这个对隐含的外部重定向URL的精简化操作是有用的而且是重要的。 下面例子一节中的第一个例子有助于理解这点。 谨记 由于此功能的存在，以[url]&lt;a href=&quot;http://thishost%5b/url%5D%E4%B8%BA%E5%89%8D%E7%BC%80%E7%9A%84%E6%97%A0%E6%9D%A1%E4%BB%B6%E5%A4%96%E9%83%A8%E9%87%8D%E5%AE%9A%E5%90%91%E5%9C%A8%E4%BD%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E6%98%AF%E6%97%A0%E6%95%88%E7%9A%84%E3%80%82&quot;&gt;&lt;img width=&quot;11&quot; height=&quot;11&quot; alt=&quot;[WWW]&quot; src=&quot;http://suijf/wiki/modern/img/moin-www.png&quot; /&gt; http://thishost[/url]为前缀的无条件外部重定向在你自己的服务器上是无效的。&lt;/a&gt; 要做这样一个自身的重定向，必须使用R标记 (见下文). 此外，Substitution还可以追加特殊标记  &lt;/p&gt;

&lt;h4 id=&quot;head-c1a783abd0c43fc6766477297a5e74ffa65e6394&quot;&gt;1.3.9. flags(要点)&lt;/h4&gt;

&lt;p&gt;作为&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteRule&quot; class=&quot;nonexistent&quot;&gt;RewriteRule&lt;/a&gt;指令的第三个参数。 Flags是一个包含以逗号分隔的下列标记的列表: &lt;/p&gt;

&lt;h5 id=&quot;head-e45a30d03374241a9225d35c8f2880f602415f03&quot;&gt;1.3.9.1. redirect|R [=code]&lt;/h5&gt;

&lt;p&gt;(强制重定向 redirect) 
&lt;/p&gt;
&lt;pre&gt;以[url]http://thishost[/url][:thisport]/(使新的URL成为一个URI) 为前缀的Substitution可以强制性执行一个外部重定向。 如果code没有指定，则产生一个HTTP响应代码302(临时性移动)。如果需要使用在300-400范围内的其他响应代码，只需在此指定这个数值即可， 另外，还可以使用下列符号名称之一: temp (默认的), permanent, seeother. 用它可以把规范化的URL反馈给客户端，如, 重写``/~''为 ``/u/''，或对/u/user加上斜杠，等等。&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;注意: 在使用这个标记时，必须确保该替换字段是一个有效的URL! 否则，它会指向一个无效的位置! 并且要记住，此标记本身只是对URL加上 &lt;tt&gt;[url]http://thishost[/url][:thisport]/&lt;/tt&gt;的前缀，重写操作仍然会继续。通常，你会希望停止重写操作而立即重定向，则还需要使用'L'标记. &lt;/p&gt;

&lt;h5 id=&quot;head-4da6a8cf7b316540ff187bfe0042a4769405a1fa&quot;&gt;1.3.9.2. forbidden|F&lt;/h5&gt;

&lt;p&gt;(强制URL为被禁止的 forbidden) &lt;/p&gt;
&lt;p&gt;强制当前URL为被禁止的，即，立即反馈一个HTTP响应代码403(被禁止的)。 使用这个标记，可以链接若干&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteConds&quot; class=&quot;nonexistent&quot;&gt;RewriteConds&lt;/a&gt;以有条件地阻塞某些URL。 &lt;/p&gt;

&lt;h5 id=&quot;head-d261957dc84b822566ac77130cebd8ade807b95b&quot;&gt;1.3.9.3. gone|G&lt;/h5&gt;

&lt;p&gt;(强制URL为已废弃的 gone) &lt;/p&gt;
&lt;p&gt;强制当前URL为已废弃的，即，立即反馈一个HTTP响应代码410(已废弃的)。 使用这个标记，可以标明页面已经被废弃而不存在了. &lt;/p&gt;

&lt;h5 id=&quot;head-a380fd30a6ec292b321280d899aedd4f01a33d37&quot;&gt;1.3.9.4. proxy|P&lt;/h5&gt;

&lt;p&gt;(强制为代理 proxy) &lt;/p&gt;
&lt;p&gt;此标记使替换成分被内部地强制为代理请求，并立即(即， 重写规则处理立即中断)把处理移交给代理模块。你必须确保此替换串是一个有效的(比如常见的以 &lt;tt&gt;[url]http://hostname[/url]开头的&lt;/tt&gt;)能够为Apache代理模块所处理的URI。使用这个标记，可以把某些远程成分映射到本地服务器名称空间， 从而增强了&lt;a href=&quot;http://suijf/suijf/UserPreferences/ProxyPass&quot; class=&quot;nonexistent&quot;&gt;ProxyPass&lt;/a&gt;指
令的功能。 注意: 要使用这个功能，代理模块必须编译在Apache服务器中。 如果你不能确定，可以检查httpd
-l的输出中是否有mod_proxy.c。
如果有，则mod_rewrite可以使用这个功能；如果没有，则必须启用mod_proxy并重新编译httpd&lt;em&gt;程序。 &lt;/em&gt;&lt;/p&gt;

&lt;h5 id=&quot;head-bee8590a2aa7204ee5f493d37802ace024ac96d1&quot;&gt;1.3.9.5. last|L&lt;/h5&gt;

&lt;p&gt;(最后一个规则 last) &lt;/p&gt;
&lt;p&gt;立即停止重写操作，并不再应用其他重写规则。
它对应于Perl中的last命令或C语言中的break命令。这个标记可以阻止当前已被重写的URL为其后继的规则所重写。
举例，使用它可以重写根路径的URL('/')为实际存在的URL, 比如, '/e/www/'. 'next|N' (重新执行 next
round) 重新执行重写操作(从第一个规则重新开始). 这时再次进行处理的URL已经不是原始的URL了，而是经最后一个重写规则处理的URL。
它对应于Perl中的next命令或C语言中的continue命令。 此标记可以重新开始重写操作，即, 立即回到循环的头部。
但是要小心，不要制造死循环! &lt;/p&gt;

&lt;h5 id=&quot;head-8d6a91578c3026e49beb23c441e190fc94935242&quot;&gt;1.3.9.6. chain|C&lt;/h5&gt;

&lt;p&gt;(与下一个规则相链接 chained) &lt;/p&gt;
&lt;p&gt;此标记使当前规则与下一个(其本身又可以与其后继规则相链接的， 并可以如此反复的)规则相链接。 它产生这样一个效果:
如果一个规则被匹配，通常会继续处理其后继规则，
即，这个标记不起作用；如果规则不能被匹配，则其后继的链接的规则会被忽略。比如，在执行一个外部重定向时，
对一个目录级规则集，你可能需要删除.www (此处不应该出现.www&lt;em&gt;的)。 &lt;/em&gt;&lt;/p&gt;

&lt;h5 id=&quot;head-b08d2296e7dc526971f278c5b649299b5b0ce882&quot;&gt;1.3.9.7. type|T=MIME-type&lt;/h5&gt;

&lt;p&gt;(强制MIME类型 type) &lt;/p&gt;
&lt;p&gt;强制目标文件的MIME类型为MIME-type。 比如，它可以用于模拟mod_alias中的&lt;a href=&quot;http://suijf/suijf/UserPreferences/ScriptAlias&quot; class=&quot;nonexistent&quot;&gt;ScriptAlias&lt;/a&gt;指令， 以内部地强制被映射目录中的所有文件的MIME类型为application/x-httpd-cgi. &lt;/p&gt;

&lt;h5 id=&quot;head-7bbc96d697995edc76d5ca350cb5eb667bb299b6&quot;&gt;1.3.9.8. nosubreq|NS&lt;/h5&gt;

&lt;p&gt;(仅用于不对内部子请求进行处理 no internal sub-request) &lt;/p&gt;
&lt;p&gt;在当前请求是一个内部子请求时，此标记强制重写引擎跳过该重写规则。比如，在mod_include试图搜索可能的目录默认文件
(index.xxx)时，
Apache会内部地产生子请求。对子请求，它不一定有用的，而且如果整个规则集都起作用，它甚至可能会引发错误。所以，可以用这个标记来排除某些规则。
&lt;/p&gt;
&lt;p&gt;根据你的需要遵循以下原则: 如果你使用了有CGI脚本的URL前缀，以强制它们由CGI脚本处理， 而对子请求处理的出错率(或者开销)很高，在这种情况下，可以使用这个标记。 &lt;/p&gt;

&lt;h5 id=&quot;head-bbc5a01abf4910f65933c2fb9c5a3bfeaa7c0733&quot;&gt;1.3.9.9. nocase|NC&lt;/h5&gt;

&lt;p&gt;(忽略大小写 no case) &lt;/p&gt;
&lt;p&gt;它使Pattern忽略大小写，即, 在Pattern与当前URL匹配时，'A-Z' 和'a-z'没有区别。 'qsappend|QSA'
(追加请求串 query string append) 此标记强制重写引擎在已有的替换串中追加一个请求串，而不是简单的替换。
如果需要通过重写规则在请求串中增加信息，就可以使用这个标记。 &lt;/p&gt;

&lt;h5 id=&quot;head-319fe02bc0df5339a8b4369aff6c606435f9f12a&quot;&gt;1.3.9.10. noescape|NE&lt;/h5&gt;

&lt;p&gt;(在输出中不对URI作转义 no URI escaping) &lt;/p&gt;
&lt;p&gt;此标记阻止mod_rewrite对重写结果应用常规的URI转义规则。 一般情况下，特殊字符(如'%', '$', ';'等)会被转义为等值的十六进制编码。 此标记可以阻止这样的转义，以允许百分号等符号出现在输出中，如： 
&lt;/p&gt;
&lt;pre&gt;RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]&lt;br /&gt;&lt;br /&gt;可以使'/foo/zed'转向到一个安全的请求'/bar?arg=P1=zed'.&lt;br /&gt;&lt;/pre&gt;

&lt;h5 id=&quot;head-3cab16941b26fc4e0ab82265f3a7597f84ba0646&quot;&gt;1.3.9.11. passthrough|PT&lt;/h5&gt;

&lt;p&gt;(移交给下一个处理器 pass through) &lt;/p&gt;
&lt;p&gt;此标记强制重写引擎将内部结构request_rec中的uri字段设置为 filename字段的值，它只是一个小修改，使之能对来自其他URI到文件名翻译器的 Alias，&lt;a href=&quot;http://suijf/suijf/UserPreferences/ScriptAlias&quot; class=&quot;nonexistent&quot;&gt;ScriptAlias&lt;/a&gt;, Redirect 等指令的输出进行后续处理。举一个能说明其含义的例子： 如果要通过mod_rewrite的重写引擎重写/abc为/def，然后通过mod_alias使/def转变为/ghi，可以这样: 
&lt;/p&gt;
&lt;pre&gt;RewriteRule ^/abc(.*) /def$1 [PT]&lt;br /&gt;Alias /def /ghi&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;如果省略了PT标记，虽然mod_rewrite运作正常， 即, 作为一个使用API的URI到文件名翻译器，
它可以重写uri=/abc/...为filename=/def/...，
但是，后续的mod_alias在试图作URI到文件名的翻译时，则会失效。 注意: 如果需要混合使用不同的包含URI到文件名翻译器的模块时，
就必须使用这个标记。。 混合使用mod_alias和mod_rewrite就是个典型的例子。 &lt;/p&gt;
&lt;p&gt;For Apache hackers 如果当前Apache API除了URI到文件名hook之外，还有一个文件名到文件名的hook，
就不需要这个标记了! 但是，如果没有这样一个hook，则此标记是唯一的解决方案。 Apache Group讨论过这个问题，并在Apache
2.0 版本中会增加这样一个hook。 'skip|S=num' (跳过后继的规则 skip)
此标记强制重写引擎跳过当前匹配规则后继的num个规则。 它可以实现一个伪if-then-else的构造:
最后一个规则是then从句，而被跳过的skip=N个规则是else从句. (它和'chain|C'标记是不同的!) 'env|E=&lt;a href=&quot;http://suijf/suijf/UserPreferences/InterWiki&quot; title=&quot;VAR&quot; class=&quot;badinterwiki&quot;&gt;&lt;img width=&quot;16&quot; height=&quot;16&quot; alt=&quot;[VAR]&quot; src=&quot;http://suijf/wiki/modern/img/moin-inter.png&quot; /&gt;VAL&lt;/a&gt;'
(设置环境变量 environment variable) 此标记使环境变量VAR的值为VAL,
VAL可以包含可扩展的反向引用的正则表达式$N和%N。
此标记可以多次使用以设置多个变量。这些变量可以在其后许多情况下被间接引用，但通常是在XSSI (via &amp;amp;lt;!--#echo
var=&amp;amp;quot;VAR&amp;amp;quot;--&amp;amp;gt;) or CGI (如 $ENV{'VAR'})中， 也可以在后继的&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteCond&quot; class=&quot;nonexistent&quot;&gt;RewriteCond&lt;/a&gt;指令的pattern中通过%{&lt;a href=&quot;http://suijf/suijf/UserPreferences/InterWiki&quot; title=&quot;ENV&quot; class=&quot;badinterwiki&quot;&gt;&lt;img width=&quot;16&quot; height=&quot;16&quot; alt=&quot;[ENV]&quot; src=&quot;http://suijf/wiki/modern/img/moin-inter.png&quot; /&gt;VAR}作引用。使用它可以从URL中剥离并记住一些信息。&lt;/a&gt; &lt;/p&gt;

&lt;h5 id=&quot;head-023435be676d5c1bbf1fbefcf48c5d8bad31c60c&quot;&gt;1.3.9.12. cookie|CO=NAME:VAL:domain[:lifetime[:path]]&lt;/h5&gt;

&lt;p&gt;(设置cookie) &lt;/p&gt;
&lt;p&gt;它在客户端浏览器上设置一个cookie。 cookie的名称是NAME，其值是VAL。
domain字段是该cookie的域，比如'.apache.org', 可选的lifetime是cookie生命期的分钟数，
可选的path是cookie的路径。 注意 绝不要忘记，在服务器级配置文件中，Pattern是作用于整个URL的。 但是在目录级配置文件中，
(一般总是和特定目录名称相同的)目录前缀会在pattern匹配时被自动删除，
而又在替换完毕后自动被加上。此特性对很多种重写是必须的，因为，如果没有这个剥离前缀的动作，就必须与其父目录去匹配，而这并不总是可行的。
但是有一个例外: 如果替换串以&lt;a href=&quot;http:///&quot;&gt;&lt;img width=&quot;11&quot; height=&quot;11&quot; alt=&quot;[WWW]&quot; src=&quot;http://suijf/wiki/modern/img/moin-www.png&quot; /&gt; http://&lt;/a&gt;&lt;em&gt;开头， 则不会附加目录前缀， 而是强制产生一个外部重定向，或者(如果使用了P标记)是一个代理操作!  &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;注意 为了对目录级配置启用重写引擎，你必须在这些文件中设置&lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteEngine&quot; class=&quot;nonexistent&quot;&gt;RewriteEngine&lt;/a&gt; On， 并且打开Options &lt;a href=&quot;http://suijf/suijf/UserPreferences/FollowSymLinks&quot; class=&quot;nonexistent&quot;&gt;FollowSymLinks&lt;/a&gt;'。 如果管理员对用户目录禁用了&lt;a href=&quot;http://suijf/suijf/UserPreferences/FollowSymLinks&quot; class=&quot;nonexistent&quot;&gt;FollowSymLinks&lt;/a&gt;， 则无法使用重写引擎。这个限制是为了安全而设置的。 以下是所有可能的替换组合及其含义: &lt;/p&gt;
&lt;p&gt;在服务器级配置中(httpd.conf) ，对这样一个请求 GET /somepath/pathinfo&lt;em&gt;: &lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;Given Rule Resulting Substitution&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^/somepath(.*) otherpath$1 not supported, because invalid!&lt;br /&gt;&lt;br /&gt;^/somepath(.*) otherpath$1 [R] not supported, because invalid!&lt;br /&gt;&lt;br /&gt;^/somepath(.*) otherpath$1 [P] not supported, because invalid!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^/somepath(.*) /otherpath$1 /otherpath/pathinfo&lt;br /&gt;&lt;br /&gt;^/somepath(.*) /otherpath$1 [R] [url]http://thishost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^/somepath(.*) /otherpath$1 [P] not supported, because silly!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^/somepath(.*) [url]http://thishost/otherpath$1[/url] /otherpath/pathinfo&lt;br /&gt;&lt;br /&gt;^/somepath(.*) [url]http://thishost/otherpath$1[/url] [R] [url]http://thishost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^/somepath(.*) [url]http://thishost/otherpath$1[/url] [P] not supported, because silly!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^/somepath(.*) [url]http://otherhost/otherpath$1[/url] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^/somepath(.*) [url]http://otherhost/otherpath$1[/url] [R] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;(the [R] flag is redundant)&lt;br /&gt;&lt;br /&gt;^/somepath(.*) [url]http://otherhost/otherpath$1[/url] [P] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via internal proxy&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;在/somepath的目录级配置中 (即, 目录/physical/path/to/somepath的.htaccess文件中包含 &lt;a href=&quot;http://suijf/suijf/UserPreferences/RewriteBase&quot; class=&quot;nonexistent&quot;&gt;RewriteBase&lt;/a&gt; /somepath) 对这样一个请求GET /somepath/localpath/pathinfo: &lt;/p&gt;

&lt;pre&gt;Given Rule Resulting Substitution&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo&lt;br /&gt;&lt;br /&gt;^localpath(.*) otherpath$1 [R] [url]http://thishost/somepath/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^localpath(.*) otherpath$1 [P] not supported, because silly!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^localpath(.*) /otherpath$1 /otherpath/pathinfo&lt;br /&gt;&lt;br /&gt;^localpath(.*) /otherpath$1 [R] [url]http://thishost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^localpath(.*) /otherpath$1 [P] not supported, because silly!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^localpath(.*) [url]http://thishost/otherpath$1[/url] /otherpath/pathinfo&lt;br /&gt;&lt;br /&gt;^localpath(.*) [url]http://thishost/otherpath$1[/url] [R] [url]http://thishost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^localpath(.*) [url]http://thishost/otherpath$1[/url] [P] not supported, because silly!&lt;br /&gt;---------------------------------------------- ----------------------------------&lt;br /&gt;^localpath(.*) [url]http://otherhost/otherpath$1[/url] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;&lt;br /&gt;^localpath(.*) [url]http://otherhost/otherpath$1[/url] [R] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via external redirection&lt;br /&gt;(the [R] flag is redundant)&lt;br /&gt;&lt;br /&gt;^localpath(.*) [url]http://otherhost/otherpath$1[/url] [P] [url]http://otherhost/otherpath/pathinfo[/url]&lt;br /&gt;via internal proxy&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;举例: &lt;/p&gt;
&lt;p&gt;要重写这种形式的URL 
&lt;/p&gt;
&lt;pre&gt;/ Language /~ Realname /.../ File&lt;br /&gt;&lt;br /&gt;为&lt;br /&gt;&lt;br /&gt;/u/ Username /.../ File . Language&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;可以把这样的对应关系保存在/path/to/file/map.txt映射文件中， 此后，只要在Apache服务器配置文件中增加下列行，即可： 
&lt;/p&gt;
&lt;pre&gt;RewriteLog /path/to/file/rewrite.log&lt;br /&gt;RewriteMap real-to-user txt:/path/to/file/map.txt&lt;br /&gt;RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1&lt;br /&gt;&lt;/pre&gt;

&lt;pre&gt;rewriterule  ^/photoblog.*$ http://localhost:8080/%{REQUEST_URI} [P]&lt;br /&gt;rewriterule  !^/top/?$ - [C]&lt;br /&gt;rewriterule  !^/groups/?$ - [C]&lt;br /&gt;rewriterule  ^/([a-zA-Z0-9]+)/?$ http://localhost:8080/photoblog/YourHomeCtrl?domain=$1  [P,L]&lt;br /&gt;&lt;/pre&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893380/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893380/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 11 Jul 2006 01:24:12 +0800</pubDate><guid isPermaLink="false">5367682@http://sdlyi.bokee.com/</guid><dc:subject>服务器配置</dc:subject><fs:srclink>http://sdlyi.bokee.com/5367682.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893380/1235476</fs:itemid></item><item><title>mod jk 安装</title><link>http://sdlyi.bokee.com/5367673.html</link><description>&lt;h1 id=&quot;title&quot;&gt;&lt;a title=&quot;点击对这个标题进行全文检索&quot; href=&quot;http://suijf/suijf/suijf/suijf/mod_jk?action=fullsearch&amp;amp;value=linkto%3A%22suijf%2Fmod+jk%22&amp;amp;context=180&quot;&gt;mod jk&lt;/a&gt;&lt;/h1&gt;
&lt;div lang=&quot;zh&quot; dir=&quot;ltr&quot; id=&quot;content&quot;&gt;

&lt;ol&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/suijf/mod_jk#head-00686baabd8cf490e57447b47463daf2a6a1088d&quot;&gt;安装流程&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;a href=&quot;http://suijf/suijf/suijf/suijf/mod_jk#head-9d9a4c23ba2ad68ad4e611c3392eeb3812609633&quot;&gt;配置流程&lt;/a&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt; &lt;/p&gt;&lt;div lang=&quot;zh&quot; dir=&quot;ltr&quot; id=&quot;Include_CPUGnav&quot;&gt;



&lt;/div&gt;
 

&lt;h3 id=&quot;head-00686baabd8cf490e57447b47463daf2a6a1088d&quot;&gt;1. 安装流程&lt;/h3&gt;


&lt;h4 id=&quot;head-222a472d9593ecaa6a879862991bd0a02c9bb689&quot;&gt;1.1. 下载包文件&lt;/h4&gt;


&lt;pre&gt;wget http://archive.apache.org/dist/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-07f7746296b0f52c8eaf444789412da74ab2d4ee&quot;&gt;1.2. 解压&lt;/h4&gt;


&lt;pre&gt;tar xzvf jakarta-tomcat-connectors-jk2-src-current.tar.gz&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-739c29bb5afbd8c115c62ea556b01e0cdcb17e70&quot;&gt;1.3. 切换路径&lt;/h4&gt;


&lt;pre&gt;/usr/local/httpd-2.0.55/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-33fd11d1c85f36432f7fd7411965f8a5f3e07684&quot;&gt;1.4. 安装前配置&lt;/h4&gt;


&lt;pre&gt;./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-java-home=/usr/java/j2sdk1.4.2_04/&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-24bce62d98ea6e5e8a7fa1ad882fdccf676bbd0b&quot;&gt;1.5. 安装&lt;/h4&gt;


&lt;pre&gt;make jk2-build-apxs&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-739c29bb5afbd8c115c62ea556b01e0cdcb17e70-2&quot;&gt;1.6. 切换路径&lt;/h4&gt;


&lt;pre&gt;cd server/apache2/&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-30abdec50b01a2df383abd80ef9836b23fe808cb&quot;&gt;1.7. 生成mod_jk&lt;/h4&gt;


&lt;pre&gt;make -f Makefile.apxs install&lt;br /&gt;&lt;/pre&gt;

&lt;h4 id=&quot;head-5037904bc81c662857bd38a6b7bf9f85c90e0c43&quot;&gt;1.8. 修改apache配置文件&lt;/h4&gt;


&lt;pre&gt;LoadModule jk2_module modules/mod_jk2.so&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;安装完成！ &lt;/p&gt;

&lt;h3 id=&quot;head-9d9a4c23ba2ad68ad4e611c3392eeb3812609633&quot;&gt;2. 配置流程&lt;/h3&gt;

&lt;p&gt;设置虚拟主机 比如，我现在有虚拟主机 vhosts.vicp.net
希望把jsp和servlet都转到tomcat去，而其他的文件比如html页面，图片等等仍然用apache解析。 Tomcat设置： 修改
tomcat/conf/server.xml，在
&amp;amp;lt;Engine&amp;amp;gt;&amp;amp;lt;/Engine&amp;amp;gt;里面再增加一个&amp;amp;lt;host/&amp;amp;gt;， &lt;/p&gt;
&lt;pre&gt;&amp;amp;lt;Host name=&amp;amp;quot;vhosts.vicp.net&amp;amp;quot; debug=&amp;amp;quot;0&amp;amp;quot; &lt;br /&gt;appBase=&amp;amp;quot;/opt/jakarta-tomcat-4.1.12-LE-jdk14/webapps/struts-example&amp;amp;quot;&lt;br /&gt;unpackWARs=&amp;amp;quot;true&amp;amp;quot; autoDeploy=&amp;amp;quot;true&amp;amp;quot;&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Alias&amp;amp;gt;localhost&amp;amp;lt;/Alias&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Alias&amp;amp;gt;www&amp;amp;lt;/Alias&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Alias&amp;amp;gt;10.0.0.10&amp;amp;lt;/Alias&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Context path=&amp;amp;quot;&amp;amp;quot; docBase=&amp;amp;quot;&amp;amp;quot; debug=&amp;amp;quot;1&amp;amp;quot;/&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Valve className=&amp;amp;quot;org.apache.catalina.valves.AccessLogValve&amp;amp;quot;&lt;br /&gt;directory=&amp;amp;quot;logs&amp;amp;quot; prefix=&amp;amp;quot;vhost.vicp.net_access_log.&amp;amp;quot; suffix=&amp;amp;quot;.txt&amp;amp;quot;&lt;br /&gt;pattern=&amp;amp;quot;common&amp;amp;quot; resolveHosts=&amp;amp;quot;false&amp;amp;quot;/&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;Logger className=&amp;amp;quot;org.apache.catalina.logger.FileLogger&amp;amp;quot;&lt;br /&gt;directory=&amp;amp;quot;logs&amp;amp;quot; prefix=&amp;amp;quot;home_log_&amp;amp;quot; suffix=&amp;amp;quot;_app_log.txt&amp;amp;quot;&lt;br /&gt;timestamp=&amp;amp;quot;true&amp;amp;quot;/&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;/Host&amp;amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;调整里面的参数和设置使之适合你的环境，当然，如果你还有其他的&amp;amp;lt;host/&amp;amp;gt;添加在后面。 &lt;/p&gt;

&lt;h4 id=&quot;head-eedf9151233373df6cb399ecbb8939c179555380&quot;&gt;2.1. 设置虚拟主机&lt;/h4&gt;

&lt;p&gt;在httpd.conf里面配置： &lt;/p&gt;
&lt;p&gt;把下面这段放到&lt;a class=&quot;nonexistent&quot; href=&quot;http://suijf/suijf/suijf/VirtualHost&quot;&gt;VirtualHost&lt;/a&gt;之前，可以从全局避免用户用apache访问WEB-INF目录。 
&lt;/p&gt;
&lt;pre&gt;&amp;amp;lt;Directory ~ &amp;amp;quot;/WEB-INF/&amp;amp;quot;&amp;amp;gt;&lt;br /&gt;Order allow,deny&lt;br /&gt;Deny from all&lt;br /&gt;&amp;amp;lt;/Directory&amp;amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;典型的&lt;a class=&quot;nonexistent&quot; href=&quot;http://suijf/suijf/suijf/VirtualHost&quot;&gt;VirtualHost&lt;/a&gt;配置样本 &lt;/p&gt;

&lt;pre&gt;&amp;amp;lt;VirtualHost _default_:80&amp;amp;gt;&lt;br /&gt;ServerName vhost.vicp.net&lt;br /&gt;DocumentRoot /home/webapp/public_html/&lt;br /&gt;DirectoryIndex index.htm index.html default.htm index.php index.jsp&lt;br /&gt;&amp;amp;lt;Location ~ &amp;amp;quot;/*.jsp|/*/servlet/*&amp;amp;quot;&amp;amp;gt;&lt;br /&gt;JkUriSet worker ajp13:localhost:8009&lt;br /&gt;&amp;amp;lt;/Location&amp;amp;gt;&lt;br /&gt;ErrorLog logs/vhosts.vicp.net-err_log&lt;br /&gt;CustomLog logs/vhosts.vicp.net-acc_log common&lt;br /&gt;&amp;amp;lt;/VirtualHost&amp;amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;这样就可以为每个不同的虚拟主机分别指定使用或者不使用jsp功能。 &lt;/p&gt;
&lt;p&gt;好了，可以开始开发和使用你的web应用了！ &lt;/p&gt;


&lt;/div&gt;
&lt;p lang=&quot;zh&quot; dir=&quot;ltr&quot; id=&quot;pageinfo&quot; class=&quot;info&quot;&gt;2006-03-30 02:09:56由&lt;span title=&quot;suijf&quot;&gt;jenves&lt;/span&gt;编辑&lt;/p&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893381/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893381/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Tue, 11 Jul 2006 01:23:23 +0800</pubDate><guid isPermaLink="false">5367673@http://sdlyi.bokee.com/</guid><dc:subject>服务器配置</dc:subject><fs:srclink>http://sdlyi.bokee.com/5367673.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893381/1235476</fs:itemid></item><item><title>测试</title><link>http://sdlyi.bokee.com/4205116.html</link><description>测试所用&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893382/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893382/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Mon, 16 Jan 2006 18:46:03 +0800</pubDate><guid isPermaLink="false">4205116@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/4205116.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893382/1235476</fs:itemid></item><item><title>Using the WebLogic XML Streaming API</title><link>http://sdlyi.bokee.com/4017235.html</link><description>&lt;!--StartFragment --&gt;&amp;amp;nbsp;&lt;!--StartFragment --&gt; Using the WebLogic XML Streaming API &lt;p class=&quot;head1&quot;&gt;Parsing an XML Document: Typical Steps&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1073319&quot;&gt;&lt;/a&gt;The following procedure describes the typical steps for using the WebLogic XML Streaming API to parse and manipulate an XML document. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087014&quot;&gt;&lt;/a&gt;The first two steps are required. The next steps you take depend on how you want to process the XML file. &lt;/p&gt;&lt;ol type=&quot;1&quot;&gt;&lt;p /&gt;&lt;li value=&quot;1&quot;&gt;&lt;a name=&quot;1073628&quot;&gt;&lt;/a&gt;Import the &lt;font class=&quot;code&quot;&gt;weblogic.xml.stream.*&lt;/font&gt; classes. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;2&quot;&gt;&lt;a name=&quot;1088941&quot;&gt;&lt;/a&gt;Get an XML stream of events from an XML file, a DOM tree, or a set of SAX events. You can also filter the XML stream to get only certain types of events, names of specific elements, and so on. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073967&quot;&gt;&amp;amp;quot;Getting an XML Input Stream&amp;amp;quot; on page&amp;amp;nbsp;4-7&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;3&quot;&gt;&lt;a name=&quot;1073653&quot;&gt;&lt;/a&gt;Iterate over the stream, returning generic &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; types. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073268&quot;&gt;&amp;amp;quot;Iterating Over the Stream&amp;amp;quot; on page&amp;amp;nbsp;4-10&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;4&quot;&gt;&lt;a name=&quot;1076268&quot;&gt;&lt;/a&gt;For each generic &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; type, determine the specific event type. Event types include the start of an XML document, the end of an element, an entity reference, and so on. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076314&quot;&gt;&amp;amp;quot;Determining the Specific XMLEvent Type&amp;amp;quot; on page&amp;amp;nbsp;4-11&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;5&quot;&gt;&lt;a name=&quot;1073762&quot;&gt;&lt;/a&gt;Get the attributes of an element. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073269&quot;&gt;&amp;amp;quot;Getting the Attributes of an Element&amp;amp;quot; on page&amp;amp;nbsp;4-15&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;6&quot;&gt;&lt;a name=&quot;1073749&quot;&gt;&lt;/a&gt;Position the stream by skipping over event, skipping to a particular event, and so on. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076241&quot;&gt;&amp;amp;quot;Positioning the Stream&amp;amp;quot; on page&amp;amp;nbsp;4-16&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;7&quot;&gt;&lt;a name=&quot;1073813&quot;&gt;&lt;/a&gt;Get the children of an element. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073282&quot;&gt;&amp;amp;quot;Getting a Substream&amp;amp;quot; on page&amp;amp;nbsp;4-17&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;8&quot;&gt;&lt;a name=&quot;1073879&quot;&gt;&lt;/a&gt;Close the stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1087407&quot;&gt;&amp;amp;quot;Closing the Input Stream&amp;amp;quot; on page&amp;amp;nbsp;4-19&lt;/a&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073356&quot;&gt;&lt;/a&gt;Example of Parsing an XML Document&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1074073&quot;&gt;&lt;/a&gt;The following program shows an example of using the XML Streaming API to parse an XML document. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1085248&quot;&gt;&lt;/a&gt;The program takes a single parameter, an XML file, that it converts into an XML input stream. It then iterates over the stream, determining the type of each event, such as the start of an XML element, the end of the XML document, and so on. The program prints out information for three types of events: start elements, end elements, and the character data that forms the body of an element. The program does nothing when it encounters the other types of events, such as comments or start of the XML document.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1085321&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;The code in bold font is described in detail in the sections following the example.&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083562&quot;&gt;&lt;/a&gt;package examples.xml.stream;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083564&quot;&gt;&lt;/a&gt;import weblogic.xml.stream.Attribute;&lt;br /&gt;import weblogic.xml.stream.AttributeIterator;&lt;br /&gt;import weblogic.xml.stream.ChangePrefixMapping;&lt;br /&gt;import weblogic.xml.stream.CharacterData;&lt;br /&gt;import weblogic.xml.stream.Comment;&lt;br /&gt;import weblogic.xml.stream.XMLEvent;&lt;br /&gt;import weblogic.xml.stream.EndDocument;&lt;br /&gt;import weblogic.xml.stream.EndElement;&lt;br /&gt;import weblogic.xml.stream.EntityReference;&lt;br /&gt;import weblogic.xml.stream.ProcessingInstruction;&lt;br /&gt;import weblogic.xml.stream.Space;&lt;br /&gt;import weblogic.xml.stream.StartDocument;&lt;br /&gt;import weblogic.xml.stream.StartPrefixMapping;&lt;br /&gt;import weblogic.xml.stream.StartElement;&lt;br /&gt;import weblogic.xml.stream.EndPrefixMapping;&lt;br /&gt;import weblogic.xml.stream.XMLInputStream;&lt;br /&gt;import weblogic.xml.stream.XMLInputStreamFactory;&lt;br /&gt;import weblogic.xml.stream.XMLName;&lt;br /&gt;import weblogic.xml.stream.XMLStreamException;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083584&quot;&gt;&lt;/a&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083587&quot;&gt;&lt;/a&gt;public class ComplexParse {&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1084136&quot;&gt;&lt;/a&gt;  /**&lt;br /&gt;   * Helper method to get a handle on a stream.&lt;br /&gt;   * Takes in a name and returns a stream.  This&lt;br /&gt;   * method usese the InputStreamFactory to create an&lt;br /&gt;   * instance of an XMLInputStream&lt;br /&gt;   * @param name The file to parse&lt;br /&gt;   * @return XMLInputStream the stream to parse&lt;br /&gt;   */&lt;br /&gt;  public XMLInputStream getStream(String name)&lt;br /&gt;    throws XMLStreamException, FileNotFoundException&lt;br /&gt;  {&lt;br /&gt;    &lt;strong&gt;&lt;font class=&quot;code&quot;&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;    XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;br /&gt;&lt;/font&gt;&lt;/strong&gt;    return stream;&lt;br /&gt;  }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1087729&quot;&gt;&lt;/a&gt;  /**&lt;br /&gt;   *  Determines the type of event, such as the start&lt;br /&gt;   *  of an element, end of a document, and so on.  If the&lt;br /&gt;   *  event is of type START_ELEMENT, END_ELEMENT, or&lt;br /&gt;   *  CHARACTER_DATA, the method prints out appropriate info;&lt;br /&gt;   *  otherwise, it does nothing.&lt;br /&gt;   *  @param event The XML event that has been parsed&lt;br /&gt;   */&lt;br /&gt;  public void parse(XMLEvent event)&lt;br /&gt;    throws XMLStreamException&lt;br /&gt;  {&lt;br /&gt;    &lt;strong&gt;&lt;font class=&quot;code&quot;&gt;switch(event.getType()) {&lt;br /&gt;    case XMLEvent.START_ELEMENT:&lt;br /&gt;      StartElement startElement = (StartElement) event;&lt;br /&gt;      System.out.print(&amp;amp;quot;&amp;amp;lt;&amp;amp;quot; + startElement.getName().getQualifiedName() );&lt;br /&gt;      AttributeIterator attributes = startElement.getAttributesAndNamespaces();&lt;br /&gt;      while(attributes.hasNext()){&lt;br /&gt;        Attribute attribute = attributes.next();&lt;br /&gt;        System.out.print(&amp;amp;quot; &amp;amp;quot; + attribute.getName().getQualifiedName() + &lt;br /&gt;                          &amp;amp;quot;='&amp;amp;quot; + attribute.getValue() + &amp;amp;quot;'&amp;amp;quot;);&lt;br /&gt;      }&lt;br /&gt;      System.out.print(&amp;amp;quot;&amp;amp;gt;&amp;amp;quot;);&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.END_ELEMENT:&lt;br /&gt;      System.out.print(&amp;amp;quot;&amp;amp;lt;/&amp;amp;quot; + event.getName().getQualifiedName() +&amp;amp;quot;&amp;amp;gt;&amp;amp;quot;);&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.SPACE:&lt;br /&gt;    case XMLEvent.CHARACTER_DATA:&lt;br /&gt;      CharacterData characterData = (CharacterData) event;&lt;br /&gt;      System.out.print(characterData.getContent());&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.COMMENT:&lt;br /&gt;      // Print comment&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.PROCESSING_INSTRUCTION:&lt;br /&gt;      // Print ProcessingInstruction&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.START_DOCUMENT:&lt;br /&gt;      // Print StartDocument&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.END_DOCUMENT:&lt;br /&gt;      // Print EndDocument&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.START_PREFIX_MAPPING:&lt;br /&gt;      // Print StartPrefixMapping&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.END_PREFIX_MAPPING:&lt;br /&gt;      // Print EndPrefixMapping&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.CHANGE_PREFIX_MAPPING:&lt;br /&gt;      // Print ChangePrefixMapping&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.ENTITY_REFERENCE:&lt;br /&gt;      // Print EntityReference&lt;br /&gt;      break;&lt;br /&gt;    case XMLEvent.NULL_ELEMENT:&lt;br /&gt;      throw new XMLStreamException(&amp;amp;quot;Attempt to write a null event.&amp;amp;quot;);&lt;br /&gt;    default:&lt;br /&gt;      throw new XMLStreamException(&amp;amp;quot;Attempt to write unknown event&lt;br /&gt;                                    [&amp;amp;quot;+event.getType()+&amp;amp;quot;]&amp;amp;quot;);&lt;br /&gt;    }&lt;br /&gt;&lt;/font&gt;&lt;/strong&gt;  }&lt;br /&gt;  /**&lt;br /&gt;   * Helper method to iterate over a stream&lt;br /&gt;   * @param name The file to parse&lt;br /&gt;   */&lt;br /&gt;  public void parse(XMLInputStream stream)&lt;br /&gt;    throws XMLStreamException&lt;br /&gt;  {&lt;br /&gt;    &lt;strong&gt;&lt;font class=&quot;code&quot;&gt;while(stream.hasNext()) {&lt;br /&gt;      XMLEvent event = stream.next();&lt;br /&gt;      parse(event);&lt;br /&gt;&lt;/font&gt;&lt;/strong&gt;    }&lt;br /&gt;    &lt;font class=&quot;code&quot;&gt;stream.close();&lt;br /&gt;&lt;/font&gt;  }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083853&quot;&gt;&lt;/a&gt;  /** Main method.   Takes a single argument: an XML file&lt;br /&gt;   *  that will be converted into an XML input stream.&lt;br /&gt;   */&lt;br /&gt;  public static void main(String args[])&lt;br /&gt;    throws Exception&lt;br /&gt;  {&lt;br /&gt;    ComplexParse complexParse= new ComplexParse();&lt;br /&gt;    complexParse.parse(complexParse.getStream(args[0]));&lt;br /&gt;  }&lt;br /&gt;}&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073967&quot;&gt;&lt;/a&gt;Getting an XML Input Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1073968&quot;&gt;&lt;/a&gt;You can use the XML Streaming API to convert a variety of objects, such as XML files, DOM trees, or SAX events, into a stream of events. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1074407&quot;&gt;&lt;/a&gt;The following example shows how to create a stream of events from an XML file:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1073478&quot;&gt;&lt;/a&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1073506&quot;&gt;&lt;/a&gt;First you create a new instance of the &lt;font class=&quot;code&quot;&gt;XMLInputStreamFactory&lt;/font&gt;, then use the factory to create a new &lt;font class=&quot;code&quot;&gt;XMLInputStream&lt;/font&gt; from the XML file referred to in the &lt;font class=&quot;code&quot;&gt;name&lt;/font&gt; variable. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1074425&quot;&gt;&lt;/a&gt;The following example shows how to create a stream from a DOM tree:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089176&quot;&gt;&lt;/a&gt;DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;br /&gt;dbf.setValidating(false);&lt;br /&gt;dbf.setNamespaceAware(true);&lt;br /&gt;DocumentBuilder db = dbf.newDocumentBuilder();&lt;br /&gt;Document doc = db.parse(new java.io.File(file));&lt;br /&gt;XMLInputStream stream = XMLInputStreamFactory.newInstance().newInputStream(doc);&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head3&quot;&gt;&lt;a name=&quot;1087149&quot;&gt;&lt;/a&gt;Getting a Buffered XML Input Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087162&quot;&gt;&lt;/a&gt;After you finish iterating over an &lt;font class=&quot;code&quot;&gt;XMLInputStream&lt;/font&gt; object, you cannot access the stream again. If, however, you need to process the stream again, such as send it to another application or iterate over it again in some other way, use a &lt;font class=&quot;code&quot;&gt;BufferedXMLInputStream&lt;/font&gt; object rather than a plain &lt;font class=&quot;code&quot;&gt;XMlInputStream&lt;/font&gt; object. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087401&quot;&gt;&lt;/a&gt;Use the &lt;font class=&quot;code&quot;&gt;newBufferedInputStream()&lt;/font&gt; method of the &lt;font class=&quot;code&quot;&gt;XMLInputStreamFactory&lt;/font&gt; class to create a buffered XMlL input stream, as shown in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1087395&quot;&gt;&lt;/a&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;BufferedXMLInputStream bufstream =&lt;br /&gt;    factory.newBufferedInputStream(factory.newInputStream(new &lt;br /&gt;    FileInputStream(name)));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1087389&quot;&gt;&lt;/a&gt;You can use the &lt;font class=&quot;code&quot;&gt;mark()&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;reset()&lt;/font&gt; methods of the &lt;font class=&quot;code&quot;&gt;BufferedXMLInputStream&lt;/font&gt; object to mark a particular spot in the stream, continue processing the stream, then reset the stream back to the marked spot. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073297&quot;&gt;Marking and Resetting a Buffered XML Input Stream&lt;/a&gt; for more information.&lt;/p&gt;&lt;p class=&quot;head3&quot;&gt;&lt;a name=&quot;1075615&quot;&gt;&lt;/a&gt;Filtering the XML Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1076481&quot;&gt;&lt;/a&gt;Filtering an XML stream refers to creating a stream that contains only specified types of events. For example, you can create a stream that contains only start elements, end elements, and the character data that make up the body of an XML element. Another example is filtering an XML stream so that only elements with a specified name appear in the stream.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1076711&quot;&gt;&lt;/a&gt;To filter an XML stream, you specify a filter class as the second parameter to the &lt;font class=&quot;code&quot;&gt;XMLInputStreamFactory.newInputStream()&lt;/font&gt; method. You specify the events that you want in the XML stream as parameters to the filter class. The following example shows how to use the &lt;font class=&quot;code&quot;&gt;TypeFilter&lt;/font&gt; class to specify that you want only start and end XML elements and character data in the resulting XML stream:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1076726&quot;&gt;&lt;/a&gt;import weblogic.xml.stream.util.TypeFilter;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089339&quot;&gt;&lt;/a&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name), &lt;br /&gt;                        new TypeFilter(XMLEvent.START_ELEMENT |&lt;br /&gt;                                       XMLEvent.END_ELEMENT |&lt;br /&gt;                                       XMLEvent.CHARACTER_DATA));&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1081303&quot;&gt;&lt;/a&gt;The following table describes the filters provided by the WebLogic XML Streaming API. They are part of the &lt;font class=&quot;code&quot;&gt;weblogic.xml.stream.util&lt;/font&gt; package.&lt;/p&gt;&lt;div class=&quot;tblmargin&quot;&gt;&lt;p class=&quot;title&quot; /&gt;&lt;p class=&quot;titletable&quot;&gt;&lt;a name=&quot;1076833&quot;&gt;&lt;/a&gt;Table 4-2 &lt;/p&gt;&lt;p /&gt;&lt;table cellspacing=&quot;0&quot; bordercolordark=&quot;#000000&quot; cellpadding=&quot;3&quot; bordercolorlight=&quot;#ffffff&quot; border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr bgcolor=&quot;#cccccc&quot;&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076839&quot;&gt;&lt;/a&gt;&lt;strong&gt;Name of Filter&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076841&quot;&gt;&lt;/a&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076843&quot;&gt;&lt;/a&gt;&lt;strong&gt;Sample Usage&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076845&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;TypeFilter&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076847&quot;&gt;&lt;/a&gt;Filter an XML stream based on specified event types, such as &lt;font class=&quot;code&quot;&gt;XMLEvent.START_ELEMENT&lt;/font&gt;, &lt;font class=&quot;code&quot;&gt;XMLEvent.END_ELEMENT&lt;/font&gt;, and so on. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076314&quot;&gt;&amp;amp;quot;Determining the Specific XMLEvent Type&amp;amp;quot; on page&amp;amp;nbsp;4-11&lt;/a&gt; for a full list of event types.&lt;/p&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089340&quot;&gt;&lt;/a&gt;TypeFilter takes an integer bitmask as input; you OR the values to create this bitmask, as shown in the sample.&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076849&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;new TypeFilter (XMLEvent.START_ELEMENT |&lt;br /&gt;XMLEvent.END_ELEMENT |&lt;br /&gt;XMLEvent.CHARACTER_DATA)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076851&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;NameFilter&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076853&quot;&gt;&lt;/a&gt;Filter an XML stream based on the name of an element in the XML document.&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076855&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;new NameFilter (&amp;amp;quot;Book&amp;amp;quot;)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076857&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;NameSpaceFilter&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076859&quot;&gt;&lt;/a&gt;Filter an XML stream based on the specified namespace URI.&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076861&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;new NameSpaceFilter (&amp;amp;quot;http://namespace.org&amp;amp;quot;)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076863&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;NamespaceTypeFilter&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076865&quot;&gt;&lt;/a&gt;Filter an XML stream based on specified event types and namespace URI. This filter combines the functionality of &lt;font class=&quot;code&quot;&gt;TypeFilter&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;NameSpaceFilter&lt;/font&gt;.&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1076867&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;new NamespaceFilter (&amp;amp;quot;http://namespace.org&amp;amp;quot;, XMLEvent.START_ELEMENT)&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089392&quot;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089393&quot;&gt;&lt;/a&gt;The example returns a stream where all start elements have the specified namespace.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p /&gt;&lt;p class=&quot;head3&quot;&gt;&lt;a name=&quot;1076679&quot;&gt;&lt;/a&gt;Creating a Custom Filter&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1088958&quot;&gt;&lt;/a&gt;You can also create your own filter if the ones included in the API do not meet your needs.&lt;/p&gt;&lt;ol type=&quot;1&quot;&gt;&lt;p /&gt;&lt;li value=&quot;1&quot;&gt;&lt;a name=&quot;1077094&quot;&gt;&lt;/a&gt;Create a class that implements the &lt;font class=&quot;code&quot;&gt;ElementFilter&lt;/font&gt; interface and contains a method called &lt;font class=&quot;code&quot;&gt;accept(XMLEvent)&lt;/font&gt;. This method tells the &lt;font class=&quot;code&quot;&gt;XMLInputStreamFactory.newInputStream()&lt;/font&gt; method whether to add a particular event to the stream or not, as shown in the following example: &lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1076610&quot;&gt;&lt;/a&gt;package my.filters;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089476&quot;&gt;&lt;/a&gt;import weblogic.xml.stream.XMLName;&lt;br /&gt;import weblogic.xml.stream.ElementFilter;&lt;br /&gt;import weblogic.xml.stream.events.NullEvent;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089475&quot;&gt;&lt;/a&gt;public class SuperDooperFilter implements ElementFilter {&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1076627&quot;&gt;&lt;/a&gt;  protected String name;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1076629&quot;&gt;&lt;/a&gt;  public SuperDooperFilter(String name)&lt;br /&gt;  {&lt;br /&gt;    this.name = name;&lt;br /&gt;  }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1076680&quot;&gt;&lt;/a&gt;  public boolean accept(XMLEvent e) {&lt;br /&gt;    if (name.equals(e.getName().getLocalName()))&lt;br /&gt;      return true;&lt;br /&gt;    return false;&lt;br /&gt;  }&lt;br /&gt;}&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;2&quot;&gt;&lt;a name=&quot;1077139&quot;&gt;&lt;/a&gt;In your XML application, be sure to import the new filter class: &lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1077224&quot;&gt;&lt;/a&gt;import my.filters.SuperDooperFilter&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;3&quot;&gt;&lt;a name=&quot;1077253&quot;&gt;&lt;/a&gt;Specify the filter as the second parameter to the &lt;font class=&quot;code&quot;&gt;newInputStream()&lt;/font&gt; method, passing to the filter class the types of events you want to appear in the XML stream in whatever format required by your filter class:&lt;/li&gt;&lt;/ol&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1077305&quot;&gt;&lt;/a&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name), &lt;br /&gt;                        new SuperDooperFilter(param));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1077063&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073268&quot;&gt;&lt;/a&gt;Iterating Over the Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1074449&quot;&gt;&lt;/a&gt;Once you have a stream of events, the next step is to methodically step through it using the &lt;font class=&quot;code&quot;&gt;XMLInputStream.next()&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;XMLInputStream.hasNext()&lt;/font&gt; methods, as shown in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1074689&quot;&gt;&lt;/a&gt;    while(stream.hasNext()) {&lt;br /&gt;      XMLEvent event = stream.next();&lt;br /&gt;      System.out.print(event);&lt;br /&gt;    }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1076314&quot;&gt;&lt;/a&gt;Determining the Specific XMLEvent Type&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1074771&quot;&gt;&lt;/a&gt;The &lt;font class=&quot;code&quot;&gt;XMLInputStream.next()&lt;/font&gt; method returns an object of type &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt;. &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; has subinterfaces that further classify what this event might be, such as the start of the XML document, the end of an element, an entity reference, and so on. The &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; interface also contains corresponding fields, or constants, as well as a set of methods that you can use to identify the actual event. The following diagram shows the hierarchy of the &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; interface and its subinterfaces:&lt;img height=&quot;365&quot; hspace=&quot;0&quot; src=&quot;http://e-docs.bea.com/wls/docs70/xml/wwimages/xml_streama.gif&quot; width=&quot;456&quot; align=&quot;middle&quot; border=&quot;0&quot; /&gt; &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1076192&quot;&gt;&lt;/a&gt;The following table lists the subclasses and fields of the &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; class that you can use to identify a particular event while parsing the XML stream.&lt;/p&gt;&lt;div class=&quot;tblmargin&quot;&gt;&lt;p class=&quot;title&quot; /&gt;&lt;p class=&quot;titletable&quot;&gt;&lt;a name=&quot;1074787&quot;&gt;&lt;/a&gt;Table 4-3 Subclasses and Fields of the XMLEvent Class&lt;/p&gt;&lt;p /&gt;&lt;table cellspacing=&quot;0&quot; bordercolordark=&quot;#000000&quot; cellpadding=&quot;3&quot; bordercolorlight=&quot;#ffffff&quot; border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr bgcolor=&quot;#cccccc&quot;&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074791&quot;&gt;&lt;/a&gt;&lt;strong&gt;XMLEvent Subclass&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074793&quot;&gt;&lt;/a&gt;&lt;strong&gt;Field of the XMLEvent Class used to Identify Subclass&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089528&quot;&gt;&lt;/a&gt;&lt;strong&gt;Method used to Identify Subclass&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074878&quot;&gt;&lt;/a&gt;&lt;strong&gt;Description of the Subclass Event&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074795&quot;&gt;&lt;/a&gt;ChangePrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074797&quot;&gt;&lt;/a&gt;CHANGE_PREFIX_MAPPING&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089530&quot;&gt;&lt;/a&gt;isChangePrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074880&quot;&gt;&lt;/a&gt;Signals that a prefix mapping has changed from an old namespace to a new namespace.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074799&quot;&gt;&lt;/a&gt;CharacterData&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074801&quot;&gt;&lt;/a&gt;CHARACTER_DATA&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089532&quot;&gt;&lt;/a&gt;isCharacterData&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074882&quot;&gt;&lt;/a&gt;Signals that the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object contains the character data from the body of the element.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074803&quot;&gt;&lt;/a&gt;Comment&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074805&quot;&gt;&lt;/a&gt;COMMENT&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089534&quot;&gt;&lt;/a&gt;isComment&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074884&quot;&gt;&lt;/a&gt;Signals that the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object contains an XML comment.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074807&quot;&gt;&lt;/a&gt;EndDocument&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074809&quot;&gt;&lt;/a&gt;END_DOCUMENT&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089536&quot;&gt;&lt;/a&gt;isEndDocument&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074886&quot;&gt;&lt;/a&gt;Signals the end of the XML document.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074811&quot;&gt;&lt;/a&gt;EndElement&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074813&quot;&gt;&lt;/a&gt;END_ELEMENT&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089538&quot;&gt;&lt;/a&gt;isEndElement&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074888&quot;&gt;&lt;/a&gt;Signals the end of an element in the XML document.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074815&quot;&gt;&lt;/a&gt;EndPrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074817&quot;&gt;&lt;/a&gt;END_PREFIX_MAPPING&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089540&quot;&gt;&lt;/a&gt;isEndPrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074890&quot;&gt;&lt;/a&gt;Signals that a prefix mapping has gone out of scope.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074819&quot;&gt;&lt;/a&gt;EntityReference&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074821&quot;&gt;&lt;/a&gt;ENTITY_REFERENCE&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089542&quot;&gt;&lt;/a&gt;isEntityReference&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074892&quot;&gt;&lt;/a&gt;Signals that the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object contains an entity reference.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074823&quot;&gt;&lt;/a&gt;ProcessingInstruction&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074825&quot;&gt;&lt;/a&gt;PROCESSING_INSTRUCTION&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089544&quot;&gt;&lt;/a&gt;isProcessingInstruction&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074894&quot;&gt;&lt;/a&gt;Signals that the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object contains a processing instruction.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074984&quot;&gt;&lt;/a&gt;Space&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074986&quot;&gt;&lt;/a&gt;SPACE&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089546&quot;&gt;&lt;/a&gt;isSpace&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074988&quot;&gt;&lt;/a&gt;Signals that the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object contains whitespace.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074827&quot;&gt;&lt;/a&gt;StartDocument&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074829&quot;&gt;&lt;/a&gt;START_DOCUMENT&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089548&quot;&gt;&lt;/a&gt;isStartDocument&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074896&quot;&gt;&lt;/a&gt;Signals the start of an XML document.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074831&quot;&gt;&lt;/a&gt;StartElement&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074833&quot;&gt;&lt;/a&gt;START_ELEMENT&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089550&quot;&gt;&lt;/a&gt;isStartElement&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074898&quot;&gt;&lt;/a&gt;Signals the start of a element in the XML document.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074835&quot;&gt;&lt;/a&gt;StartPrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074837&quot;&gt;&lt;/a&gt;START_PREFIX_MAPPING&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1089552&quot;&gt;&lt;/a&gt;isStartPrefixMapping&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1074900&quot;&gt;&lt;/a&gt;Signals that a prefix mapping has started its scope.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p /&gt;&lt;p&gt;&lt;a name=&quot;1075105&quot;&gt;&lt;/a&gt;The following example shows how to use the Java &lt;font class=&quot;code&quot;&gt;case&lt;/font&gt; statement to determine the particular type of event that was returned by the &lt;font class=&quot;code&quot;&gt;XMLInputStream.next()&lt;/font&gt; method. For simplicity, the example simply prints that an event has been found; later sections show further processing of the event.&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079685&quot;&gt;&lt;/a&gt;    switch(event.getType()) {&lt;br /&gt;    case XMLEvent.START_ELEMENT:&lt;br /&gt;      // Start of an element&lt;br /&gt;      System.out.println (&amp;amp;quot;Start Element\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079690&quot;&gt;&lt;/a&gt;    case XMLEvent.END_ELEMENT:&lt;br /&gt;      // End of an element&lt;br /&gt;      System.out.println (&amp;amp;quot;End Element\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079694&quot;&gt;&lt;/a&gt;    case XMLEvent.PROCESSING_INSTRUCTION:&lt;br /&gt;      // Processing Instruction&lt;br /&gt;      System.out.println (&amp;amp;quot;Processing instruction\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079698&quot;&gt;&lt;/a&gt;    case XMLEvent.SPACE:&lt;br /&gt;      // Whitespace&lt;br /&gt;      System.out.println (&amp;amp;quot;White space\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079702&quot;&gt;&lt;/a&gt;    case XMLEvent.CHARACTER_DATA:&lt;br /&gt;      // Character data&lt;br /&gt;      System.out.println (&amp;amp;quot;Character data\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079706&quot;&gt;&lt;/a&gt;    case XMLEvent.COMMENT:&lt;br /&gt;      // Comment&lt;br /&gt;      System.out.println (&amp;amp;quot;Comment\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079710&quot;&gt;&lt;/a&gt;    case XMLEvent.START_DOCUMENT:&lt;br /&gt;      // Start of the XML document&lt;br /&gt;      System.out.println (&amp;amp;quot;Start Document\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079714&quot;&gt;&lt;/a&gt;    case XMLEvent.END_DOCUMENT:&lt;br /&gt;      // End of the XML Document&lt;br /&gt;      System.out.println (&amp;amp;quot;End Document\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079718&quot;&gt;&lt;/a&gt;    case XMLEvent.START_PREFIX_MAPPING:&lt;br /&gt;      // The start of a prefix mapping scope&lt;br /&gt;      System.out.println (&amp;amp;quot;Start prefix mapping\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079722&quot;&gt;&lt;/a&gt;    case XMLEvent.END_PREFIX_MAPPING:&lt;br /&gt;      // The end of a prefix mapping scope&lt;br /&gt;      System.out.println (&amp;amp;quot;End prefix mapping\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079726&quot;&gt;&lt;/a&gt;    case XMLEvent.CHANGE_PREFIX_MAPPING:&lt;br /&gt;      // Prefix mapping has changed namespaces&lt;br /&gt;      System.out.println (&amp;amp;quot;Change prefix mapping\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079730&quot;&gt;&lt;/a&gt;    case XMLEvent.ENTITY_REFERENCE:&lt;br /&gt;      // An entity reference&lt;br /&gt;      System.out.println (&amp;amp;quot;Entity reference\n&amp;amp;quot;);&lt;br /&gt;      break;&lt;br /&gt;    default:&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1079735&quot;&gt;&lt;/a&gt;      throw new XMLStreamException(&amp;amp;quot;Attempt to parse unknown event &lt;br /&gt;                                    [&amp;amp;quot; + event.getType() + &amp;amp;quot;]&amp;amp;quot;);&lt;br /&gt;    }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073269&quot;&gt;&lt;/a&gt;Getting the Attributes of an Element&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1075434&quot;&gt;&lt;/a&gt;To get the attributes of an element in an XML document, you must first cast the &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; object that was returned by the &lt;font class=&quot;code&quot;&gt;XMLInputStream.next()&lt;/font&gt; method to a &lt;font class=&quot;code&quot;&gt;StartElement&lt;/font&gt; object. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1075451&quot;&gt;&lt;/a&gt;Because you do not know how many attributes an element might have, you must first create an &lt;font class=&quot;code&quot;&gt;AttributeIterator&lt;/font&gt; object to contain the entire list of attributes, and then iterate over the list until there are no more attributes. The following example describes how to do this as part of the &lt;font class=&quot;code&quot;&gt;START_ELEMENT&lt;/font&gt; case of the &lt;font class=&quot;code&quot;&gt;switch&lt;/font&gt; statement shown in &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073268&quot;&gt;&amp;amp;quot;Iterating Over the Stream&amp;amp;quot; on page&amp;amp;nbsp;4-10&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1075494&quot;&gt;&lt;/a&gt;case XMLEvent.START_ELEMENT:&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1075495&quot;&gt;&lt;/a&gt;    StartElement startElement = (StartElement) event;&lt;br /&gt;    System.out.print(&amp;amp;quot;&amp;amp;lt;&amp;amp;quot; + startElement.getName().getQualifiedName() );&lt;br /&gt;    AttributeIterator attributes = startElement.getAttributesAndNamespaces();&lt;br /&gt;    while(attributes.hasNext()){&lt;br /&gt;      Attribute attribute = attributes.next();&lt;br /&gt;      System.out.print(&amp;amp;quot; &amp;amp;quot; + attribute.getName().getQualifiedName() + &lt;br /&gt;                        &amp;amp;quot;='&amp;amp;quot; + attribute.getValue() + &amp;amp;quot;'&amp;amp;quot;);&lt;br /&gt;    }&lt;br /&gt;    System.out.print(&amp;amp;quot;&amp;amp;gt;&amp;amp;quot;);&lt;br /&gt;    break;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1076239&quot;&gt;&lt;/a&gt;The example first creates a &lt;font class=&quot;code&quot;&gt;StartElement&lt;/font&gt; object by casting the returned &lt;font class=&quot;code&quot;&gt;XMLEvent&lt;/font&gt; to &lt;font class=&quot;code&quot;&gt;StartElement&lt;/font&gt;. It then creates an &lt;font class=&quot;code&quot;&gt;AttributeIterator&lt;/font&gt; object using the method &lt;font class=&quot;code&quot;&gt;StartElement.getAttributesAndNamespaces()&lt;/font&gt;, and iterates over the attributes using the &lt;font class=&quot;code&quot;&gt;AttributeIterator.hasNext()&lt;/font&gt; method. For each &lt;font class=&quot;code&quot;&gt;Attribute&lt;/font&gt;, it uses the &lt;font class=&quot;code&quot;&gt;Attributes.getName().getQualifiedName()&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;Attribute.getValue()&lt;/font&gt; methods to return the name and value of the attribute.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1089634&quot;&gt;&lt;/a&gt;You can also use the &lt;font class=&quot;code&quot;&gt;getNamespace()&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;getAttributes()&lt;/font&gt; methods to return just the namespaces or attributes on their own.&lt;/p&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1076241&quot;&gt;&lt;/a&gt;Positioning the Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1080059&quot;&gt;&lt;/a&gt;The following table describes the methods of the &lt;font class=&quot;code&quot;&gt;XMLInputStream&lt;/font&gt; interface that you can use to skip ahead to specific locations in the stream.&lt;/p&gt;&lt;div class=&quot;tblmargin&quot;&gt;&lt;p class=&quot;title&quot; /&gt;&lt;p class=&quot;titletable&quot;&gt;&lt;a name=&quot;1080222&quot;&gt;&lt;/a&gt;Table 4-4 Methods Used to Position the Input Stream&lt;/p&gt;&lt;p /&gt;&lt;table cellspacing=&quot;0&quot; bordercolordark=&quot;#000000&quot; cellpadding=&quot;3&quot; bordercolorlight=&quot;#ffffff&quot; border=&quot;1&quot;&gt;&lt;tbody&gt;&lt;tr bgcolor=&quot;#cccccc&quot;&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080224&quot;&gt;&lt;/a&gt;&lt;strong&gt;Method of XMLInputStream &lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;th valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;b&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080357&quot;&gt;&lt;/a&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/p&gt;&lt;/b&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080226&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;skip()&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080359&quot;&gt;&lt;/a&gt;Positions the input stream to the next stream event. &lt;/p&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080723&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;The next event might not necessarily be an actual element in the XML file; for example, it could be a comment or white space.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080228&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;skip(int)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080361&quot;&gt;&lt;/a&gt;Positions the input stream to the next event of this type. &lt;/p&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080669&quot;&gt;&lt;/a&gt;Examples of event types are &lt;font class=&quot;code&quot;&gt;XMLEvent.START_ELEMENT&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;XMLEvent.END_DOCUMENT&lt;/font&gt;. Refer to &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074787&quot;&gt;Table&amp;amp;nbsp;4-3&lt;/a&gt; for the full list of event types.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080230&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;skip(XMLName)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080363&quot;&gt;&lt;/a&gt;Positions the input stream to the next event of this name. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080232&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;skip(XMLName, int)&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080365&quot;&gt;&lt;/a&gt;Positions the input stream to the next event of this name and type.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080234&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;skipElement()&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080367&quot;&gt;&lt;/a&gt;Skips to the next element (does not skip to the sub-elements of the current element).&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080236&quot;&gt;&lt;/a&gt;&lt;font class=&quot;code&quot;&gt;peek()&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign=&quot;top&quot; align=&quot;left&quot;&gt;&lt;p class=&quot;table&quot;&gt;&lt;a name=&quot;1080369&quot;&gt;&lt;/a&gt;Checks the next event without actually reading it from the stream.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p /&gt;&lt;p&gt;&lt;a name=&quot;1081171&quot;&gt;&lt;/a&gt;The following example shows how you can modify the basic code for iterating over an input stream to skip over the character data in the body of an XML element:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1081188&quot;&gt;&lt;/a&gt;    while(stream.hasNext()) {&lt;br /&gt;      XMLEvent peek = stream.peek();&lt;br /&gt;      if (peek.getType() == XMLEvent.CHARACTER_DATA ) {&lt;br /&gt;        stream.skip();&lt;br /&gt;        continue;&lt;br /&gt;      }&lt;br /&gt;      XMLEvent event = stream.next();&lt;br /&gt;      parse(event);&lt;br /&gt;    }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1081173&quot;&gt;&lt;/a&gt;The example shows how to use the &lt;font class=&quot;code&quot;&gt;XMLInputStream.peek()&lt;/font&gt; method to determine the next event on the stream. If the type of event is &lt;font class=&quot;code&quot;&gt;XMLEvent.CHARACTER_DATA&lt;/font&gt;, then skip the event and go to the next one.&lt;/p&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073282&quot;&gt;&lt;/a&gt;Getting a Substream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1077868&quot;&gt;&lt;/a&gt;Use the &lt;font class=&quot;code&quot;&gt;XMLInputStream.getSubStream()&lt;/font&gt; method to get a copy of the next element, including all its subelements. The &lt;font class=&quot;code&quot;&gt;getSubstream()&lt;/font&gt; method returns an &lt;font class=&quot;code&quot;&gt;XMLInputStream&lt;/font&gt; object. Your position in the parent stream (or the stream from which you called &lt;font class=&quot;code&quot;&gt;getSubStream()&lt;/font&gt;) does not move. In the parent stream, if you want to skip the element you just got with &lt;font class=&quot;code&quot;&gt;getSubStream()&lt;/font&gt;, use the &lt;font class=&quot;code&quot;&gt;skipElement()&lt;/font&gt; method.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1086474&quot;&gt;&lt;/a&gt;The &lt;font class=&quot;code&quot;&gt;getSubStream()&lt;/font&gt; method keeps a count of the &lt;font class=&quot;code&quot;&gt;START_ELEMENT&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;END_ELEMENT&lt;/font&gt; events it encounters, and as soon as the number is equal (or in other words, as soon as it finds the complete next element) it stops and returns the resulting substream as an &lt;font class=&quot;code&quot;&gt;XMLInputStream&lt;/font&gt; object. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1082264&quot;&gt;&lt;/a&gt;For example, assume that you are using the XML Streaming API to parse the following XML document, but you are only interested in the substream delineated by the &lt;font class=&quot;code&quot;&gt;&amp;amp;lt;content&amp;amp;gt;&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;&amp;amp;lt;/content&amp;amp;gt;&lt;/font&gt; tags:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1081424&quot;&gt;&lt;/a&gt;&amp;amp;lt;book&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;title&amp;amp;gt;The History of the World&amp;amp;lt;/title&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;author&amp;amp;gt;Juliet Shackell&amp;amp;lt;/author&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;publisher&amp;amp;gt;CrazyDays Publishing&amp;amp;lt;/publisher&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;content&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;chapter title='Just a Speck of Dust'&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;synopsis&amp;amp;gt;The world as a speck of dust&amp;amp;lt;/synopsis&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;para&amp;amp;gt;Once the world was just a speck of dust...&amp;amp;lt;/para&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;/chapter&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;chapter title='Life Appears'&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;synopsis&amp;amp;gt;Move over dust, here comes life.&amp;amp;lt;/synopsis&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;para&amp;amp;gt;Happily, the dust got a companion: life...&amp;amp;lt;/para&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;/chapter&amp;amp;gt;&lt;br /&gt;   &amp;amp;lt;/content&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;/book&amp;amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1081636&quot;&gt;&lt;/a&gt;The following code fragment shows how you can skip to the &lt;font class=&quot;code&quot;&gt;&amp;amp;lt;content&amp;amp;gt;&lt;/font&gt; start element tag, get the substream, and parse it using a separate &lt;font class=&quot;code&quot;&gt;ComplexParse&lt;/font&gt; object:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086555&quot;&gt;&lt;/a&gt;     if (stream.skip( ElementFactory.createXMLName(&amp;amp;quot;content&amp;amp;quot;)))&lt;br /&gt;       {&lt;br /&gt;          ComplexParse complexParse = new ComplexParse();&lt;br /&gt;          complexParse.parse(stream.getSubStream());&lt;br /&gt;       }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1086519&quot;&gt;&lt;/a&gt;When you call this method on the previous XML document, you get the following output:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086695&quot;&gt;&lt;/a&gt;&amp;amp;lt;content&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;chapter title='Just a Speck of Dust'&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;synopsis&amp;amp;gt;The world as a speck of dust&amp;amp;lt;/synopsis&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;para&amp;amp;gt;Once the world was just a speck of dust...&amp;amp;lt;/para&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;/chapter&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;chapter title='Life Appears'&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;synopsis&amp;amp;gt;Move over dust, here comes life.&amp;amp;lt;/synopsis&amp;amp;gt;&lt;br /&gt;        &amp;amp;lt;para&amp;amp;gt;Happily, the dust got a companion: life...&amp;amp;lt;/para&amp;amp;gt;&lt;br /&gt;      &amp;amp;lt;/chapter&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;/content&amp;amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1073297&quot;&gt;&lt;/a&gt;Marking and Resetting a Buffered XML Input Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087423&quot;&gt;&lt;/a&gt;If you are using a &lt;font class=&quot;code&quot;&gt;BufferedXMLInputStream&lt;/font&gt; object, you can use the &lt;font class=&quot;code&quot;&gt;mark()&lt;/font&gt; and &lt;font class=&quot;code&quot;&gt;reset()&lt;/font&gt; methods to mark the stream at a particular spot, process the stream, and then subsequently reset the stream back to the marked spot. These methods are useful if you want to further manipulate the stream after initially iterating over it. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1089716&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;If you read a buffered stream without marking it, you cannot access what you've just read. In other words, just because the stream is buffered, it does not automatically mean you can reread it. You must mark it first.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087453&quot;&gt;&lt;/a&gt;The following example shows a typical use of the &lt;font class=&quot;code&quot;&gt;BufferedXMLInputStream&lt;/font&gt; object:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089707&quot;&gt;&lt;/a&gt;    XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;    BufferedXMLInputStream bufstream =&lt;br /&gt;    factory.newBufferedInputStream(factory.newInputStream(new &lt;br /&gt;                FileInputStream(name)));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089697&quot;&gt;&lt;/a&gt;    // mark the start of the stream&lt;br /&gt;    bufstream.mark();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1087486&quot;&gt;&lt;/a&gt;    // process it locally&lt;br /&gt;    bufferedParse.parse(bufstream);&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1087490&quot;&gt;&lt;/a&gt;    // reset the stream to the mark&lt;br /&gt;    bufstream.reset();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1087494&quot;&gt;&lt;/a&gt;    // send stream off to another application&lt;br /&gt;    ComplexParse complexParse =  new ComplexParse();&lt;br /&gt;    complexParse.parse(bufstream);&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1087407&quot;&gt;&lt;/a&gt;Closing the Input Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1086524&quot;&gt;&lt;/a&gt;It is good programming practice to explicitly close the XML input stream when you are finished with it. To close an input stream, use the &lt;font class=&quot;code&quot;&gt;XMLInputStream.close()&lt;/font&gt; method, as shown in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1077834&quot;&gt;&lt;/a&gt;// close the input stream&lt;br /&gt;input.close();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;amp;nbsp;&lt;/p&gt;&lt;hr noshade=&quot;true&quot; /&gt;&lt;p class=&quot;head1&quot;&gt;&lt;a name=&quot;1074012&quot;&gt;&lt;/a&gt;Generating a New XML Document: Typical Steps&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087063&quot;&gt;&lt;/a&gt;The following procedure describes the typical steps for using the WebLogic XML Streaming API to generate a new XML document. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1087064&quot;&gt;&lt;/a&gt;The first two steps are required. The next steps you take depend on how you want to generate the XML file. &lt;/p&gt;&lt;ol type=&quot;1&quot;&gt;&lt;p /&gt;&lt;li value=&quot;1&quot;&gt;&lt;a name=&quot;1089026&quot;&gt;&lt;/a&gt;Import the &lt;font class=&quot;code&quot;&gt;weblogic.xml.stream.*&lt;/font&gt; classes. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;2&quot;&gt;&lt;a name=&quot;1089029&quot;&gt;&lt;/a&gt;Create an XML output stream to which to write the XML document. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074017&quot;&gt;&amp;amp;quot;Creating an XML Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-22&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;3&quot;&gt;&lt;a name=&quot;1077527&quot;&gt;&lt;/a&gt;Add events to the XML output stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074020&quot;&gt;&amp;amp;quot;Adding Elements to the Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-23&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;4&quot;&gt;&lt;a name=&quot;1077540&quot;&gt;&lt;/a&gt;Add attributes to the XML output stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074021&quot;&gt;&amp;amp;quot;Adding Attributes to an Element on the Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-24&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;5&quot;&gt;&lt;a name=&quot;1077555&quot;&gt;&lt;/a&gt;Add an input stream to the output stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074022&quot;&gt;&amp;amp;quot;Adding an Input Stream to an Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-25&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;6&quot;&gt;&lt;a name=&quot;1077568&quot;&gt;&lt;/a&gt;Print the output stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1083477&quot;&gt;&amp;amp;quot;Printing an Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-26&lt;/a&gt;. &lt;p /&gt;&lt;/li&gt;&lt;li value=&quot;7&quot;&gt;&lt;a name=&quot;1077475&quot;&gt;&lt;/a&gt;Close the output stream. See &lt;a href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074024&quot;&gt;&amp;amp;quot;Closing the Output Stream&amp;amp;quot; on page&amp;amp;nbsp;4-26&lt;/a&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074015&quot;&gt;&lt;/a&gt;Example of Generating an XML Document&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1077595&quot;&gt;&lt;/a&gt;The following program shows an example of using the XML Streaming API to generate an XML document. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1086110&quot;&gt;&lt;/a&gt;The program first creates an output stream based on a &lt;font class=&quot;code&quot;&gt;PrintWriter&lt;/font&gt; object, then adds elements to the output stream to create a simple XML purchase order, described in the comments of the program. The program also shows how to add an input stream based on a separate XML file to the output stream.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1085396&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;The topics following the example describe it in more detail.&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085406&quot;&gt;&lt;/a&gt;package examples.xml.stream;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085408&quot;&gt;&lt;/a&gt;import weblogic.xml.stream.XMLInputStream;&lt;br /&gt;import weblogic.xml.stream.XMLOutputStream;&lt;br /&gt;import weblogic.xml.stream.XMLInputStreamFactory;&lt;br /&gt;import weblogic.xml.stream.XMLName;&lt;br /&gt;import weblogic.xml.stream.XMLEvent;&lt;br /&gt;import weblogic.xml.stream.StartElement;&lt;br /&gt;import weblogic.xml.stream.EndElement;&lt;br /&gt;import weblogic.xml.stream.Attribute;&lt;br /&gt;import weblogic.xml.stream.ElementFactory;&lt;br /&gt;import weblogic.xml.stream.XMLStreamException;&lt;br /&gt;import weblogic.xml.stream.XMLOutputStreamFactory;&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085420&quot;&gt;&lt;/a&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt;import java.io.PrintWriter;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085424&quot;&gt;&lt;/a&gt;/**&lt;br /&gt; * Program that prints out a very simple purchase order that looks&lt;br /&gt; * like the following:&lt;br /&gt; *&lt;br /&gt; * &amp;amp;lt;purchase_order&amp;amp;gt;&lt;br /&gt; *  &amp;amp;lt;name&amp;amp;gt;Juliet Shackell&amp;amp;lt;/name&amp;amp;gt;&lt;br /&gt; *  &amp;amp;lt;item id=&amp;amp;quot;1234&amp;amp;quot; quantity=&amp;amp;quot;2&amp;amp;quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;br /&gt; *  &amp;amp;lt;!-- this is a comment--&amp;amp;gt;&lt;br /&gt; *  &amp;amp;lt;another_file&amp;amp;gt;&lt;br /&gt; *    This comes from another file called &amp;amp;quot;another_file.xml&amp;amp;quot;&lt;br /&gt; *  &amp;amp;lt;/another_file&amp;amp;gt;&lt;br /&gt; * &amp;amp;lt;/purchase_order&amp;amp;gt;&lt;br /&gt; *&lt;br /&gt; * In the preceding XML file, the &amp;amp;lt;another_file&amp;amp;gt; element is actually another&lt;br /&gt; * XML file that is passed as an argument to the program, converted into an&lt;br /&gt; * XMLInputStream, then added to the output stream.&lt;br /&gt; */&lt;br /&gt;public class PrintPurchaseOrder {&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085444&quot;&gt;&lt;/a&gt;  /**&lt;br /&gt;   * Helper method to get a handle on a stream.&lt;br /&gt;   * Takes in a name and returns a stream.  This&lt;br /&gt;   * method uses the InputStreamFactory to create an&lt;br /&gt;   * instance of an XMLInputStream&lt;br /&gt;   * @param name The file to parse&lt;br /&gt;   * @return XMLInputStream the stream to parse&lt;br /&gt;   */&lt;br /&gt;  public XMLInputStream getInputStream(String name)&lt;br /&gt;    throws XMLStreamException, FileNotFoundException&lt;br /&gt;  {&lt;br /&gt;    XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;    XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;br /&gt;    return stream;&lt;br /&gt;  }&lt;br /&gt;  public static void main(String args[])&lt;br /&gt;    throws Exception&lt;br /&gt;  {&lt;br /&gt;    PrintPurchaseOrder printer = new PrintPurchaseOrder();&lt;br /&gt;    //&lt;br /&gt;    // Create an output stream.&lt;br /&gt;    //&lt;br /&gt;    XMLOutputStreamFactory factory = XMLOutputStreamFactory.newInstance();&lt;br /&gt;    XMLOutputStream output = factory.newOutputStream(new           &lt;br /&gt;                                        PrintWriter(System.out,true));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085518&quot;&gt;&lt;/a&gt;   // add the &amp;amp;lt;purchase_order&amp;amp;gt; root element&lt;br /&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;purchase_order&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085523&quot;&gt;&lt;/a&gt;   // add the &amp;amp;lt;name&amp;amp;gt; element&lt;br /&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;name&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;Juliet Shackell&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;name&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085531&quot;&gt;&lt;/a&gt;   // add the &amp;amp;lt;item&amp;amp;gt; element along with the id and quantity attributes&lt;br /&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;id&amp;amp;quot;,&amp;amp;quot;1234&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;quantity&amp;amp;quot;,&amp;amp;quot;2&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;Fabulous Chair&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085541&quot;&gt;&lt;/a&gt;    // add a comment&lt;br /&gt;   output.add(&amp;amp;quot;&amp;amp;lt;!-- this is a comment--&amp;amp;gt;&amp;amp;quot;);&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086017&quot;&gt;&lt;/a&gt;   // create an input stream from each XML file argument then add it to the output&lt;br /&gt;   for (int i=0; i &amp;amp;lt; args.length; i++)&lt;br /&gt;   //&lt;br /&gt;   // Get an input stream and add it to the output stream&lt;br /&gt;   //&lt;br /&gt;   output.add(printer.getInputStream(args[i]));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086067&quot;&gt;&lt;/a&gt;    // Finally, end the root &amp;amp;quot;purchase_order&amp;amp;quot; element&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;purchase_order&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;)); &lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086095&quot;&gt;&lt;/a&gt;    //&lt;br /&gt;    // Print the results to the screen&lt;br /&gt;    //&lt;br /&gt;    output.flush();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1085595&quot;&gt;&lt;/a&gt;   // Close the output streams&lt;br /&gt;   output.close();&lt;br /&gt;  }&lt;br /&gt;}&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1086906&quot;&gt;&lt;/a&gt;The preceding program produces the following output:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086918&quot;&gt;&lt;/a&gt;&amp;amp;lt;purchase_order&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;name&amp;amp;gt;Juliet Shackell&amp;amp;lt;/name&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;item id=&amp;amp;quot;1234&amp;amp;quot; quantity=&amp;amp;quot;2&amp;amp;quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;!-- this is a comment--&amp;amp;gt;&lt;br /&gt;  &amp;amp;lt;another_file&amp;amp;gt;&lt;br /&gt;     This is from another file.&lt;br /&gt;  &amp;amp;lt;/another_file&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;/purchase_order&amp;amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074017&quot;&gt;&lt;/a&gt;Creating an XML Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1077631&quot;&gt;&lt;/a&gt;One of the first steps in generating an XML document using the Weblogic XML Streaming API is to create an output stream which holds the document as it is being built. Creating an XML output stream is similar to creating an input stream: you first create an instance of the &lt;font class=&quot;code&quot;&gt;XMLOutputStreamFactory&lt;/font&gt; and then create an output stream with the &lt;font class=&quot;code&quot;&gt;XMLOutputStreamFactory.newOutputStream()&lt;/font&gt; method, as shown in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1077652&quot;&gt;&lt;/a&gt;	    XMLOutputStreamFactory factory = XMLOutputStreamFactory.newInstance();&lt;br /&gt;    XMLOutputStream output = factory.newOutputStream(new&lt;br /&gt;                              PrintWriter(System.out,true));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1077660&quot;&gt;&lt;/a&gt;The following example shows how to create an &lt;font class=&quot;code&quot;&gt;XMLOutputStream&lt;/font&gt; based on a DOM tree:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1089842&quot;&gt;&lt;/a&gt;    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;br /&gt;    dbf.setValidating(false);&lt;br /&gt;    dbf.setNamespaceAware(true);&lt;br /&gt;    Document doc = dbf.newDocumentBuilder().newDocument();&lt;br /&gt;    XMLOutputStream out =&lt;br /&gt;         XMLOutputStreamFactory.newInstance().newOutputStream(doc);&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1089798&quot;&gt;&lt;/a&gt;You can use the &lt;font class=&quot;code&quot;&gt;XMLOutputStreamFactory.newOutputStream()&lt;/font&gt; method to create an output stream based on the following four Java objects, depending on what the final form of the XML document will be (such as a file on the operating system, a DOM tree, and so on):&lt;/p&gt;&lt;ul type=&quot;square&quot;&gt;&lt;p&gt;&lt;a name=&quot;1077691&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;li type=&quot;square&quot;&gt;&lt;font class=&quot;code&quot;&gt;java.io.OutputStream&lt;/font&gt; &lt;p&gt;&lt;a name=&quot;1077692&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li type=&quot;square&quot;&gt;&lt;font class=&quot;code&quot;&gt;java.io.Writer&lt;/font&gt; &lt;p&gt;&lt;a name=&quot;1077694&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li type=&quot;square&quot;&gt;&lt;font class=&quot;code&quot;&gt;org.xml.sax.ContentHandler&lt;/font&gt; &lt;p&gt;&lt;a name=&quot;1077685&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li type=&quot;square&quot;&gt;&lt;font class=&quot;code&quot;&gt;org.w3c.dom.Document&lt;/font&gt; &lt;/li&gt;&lt;/ul&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074020&quot;&gt;&lt;/a&gt;Adding Elements to the Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1077739&quot;&gt;&lt;/a&gt;Use the &lt;font class=&quot;code&quot;&gt;XMLOutputStream.add(XMLEvent)&lt;/font&gt; method to add elements to the output stream. Use the &lt;font class=&quot;code&quot;&gt;ElementFactory&lt;/font&gt; to create the particular element.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1082954&quot;&gt;&lt;/a&gt;The &lt;font class=&quot;code&quot;&gt;ElementFactory&lt;/font&gt; interface includes methods to create each type of element; the general format is &lt;font class=&quot;code&quot;&gt;ElementFactory.create&lt;/font&gt;&lt;em&gt;XXX&lt;/em&gt;&lt;font class=&quot;code&quot;&gt;()&lt;/font&gt; where &lt;em&gt;&lt;font class=&quot;code&quot;&gt;XXX&lt;/font&gt;&lt;/em&gt; refers to the particular element, such as &lt;font class=&quot;code&quot;&gt;createStartElement()&lt;/font&gt;, &lt;font class=&quot;code&quot;&gt;createCharacterData()&lt;/font&gt;, and so on. You can create most elements by passing the name as a &lt;font class=&quot;code&quot;&gt;String&lt;/font&gt; or as an &lt;font class=&quot;code&quot;&gt;XMLName&lt;/font&gt;.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1089870&quot;&gt;&lt;/a&gt;&lt;strong&gt;Warning: &lt;/strong&gt;The &lt;font class=&quot;code&quot;&gt;XMLOutputStream&lt;/font&gt; does not validate your XML.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1082972&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;Each time you create a start element, you must explicitly also create an end element at some point. The same rule applies to creating a start document. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1082967&quot;&gt;&lt;/a&gt;For example, assume you want to create the following snippet of XML:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083032&quot;&gt;&lt;/a&gt;&amp;amp;lt;name&amp;amp;gt;Georgina Shackell Green&amp;amp;lt;/name&amp;amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1083328&quot;&gt;&lt;/a&gt;The Java code to add this element to an output stream is as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083339&quot;&gt;&lt;/a&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;name&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;Georgina Shackell Green&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;name&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1083330&quot;&gt;&lt;/a&gt;The final &lt;font class=&quot;code&quot;&gt;createCharacterData()&lt;/font&gt; method adds a newline character to the output stream. This is optional, but useful if you want to create human-readable XML.&lt;/p&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074021&quot;&gt;&lt;/a&gt;Adding Attributes to an Element on the Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1083083&quot;&gt;&lt;/a&gt;Use the &lt;font class=&quot;code&quot;&gt;XMLOutputStream.add(Attribute)&lt;/font&gt; to add attributes to an element you have just created. Use the &lt;font class=&quot;code&quot;&gt;ElementFactory.createAttribute()&lt;/font&gt; method to create a particular attribute. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1083086&quot;&gt;&lt;/a&gt;For example, assume you want to create the following snippet of XML:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083087&quot;&gt;&lt;/a&gt;&amp;amp;lt;item id=&amp;amp;quot;1234&amp;amp;quot; quantity=&amp;amp;quot;2&amp;amp;quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1083395&quot;&gt;&lt;/a&gt;The Java code to add this element to an output stream is as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083396&quot;&gt;&lt;/a&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;id&amp;amp;quot;,&amp;amp;quot;1234&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;quantity&amp;amp;quot;,&amp;amp;quot;2&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;Fabulous Chair&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a name=&quot;1083223&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;Be sure you add attributes to an element &lt;em&gt;after&lt;/em&gt; you create the start element but &lt;em&gt;before&lt;/em&gt; you create the corresponding end element. Otherwise, although your code will compile successfully, you will get a runtime error when you try to run the program. For example, the following code returns an error because the attributes are added to the &lt;font class=&quot;code&quot;&gt;&amp;amp;lt;item&amp;amp;gt;&lt;/font&gt; element &lt;em&gt;after&lt;/em&gt; the element has been explicitly ended:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083413&quot;&gt;&lt;/a&gt;   output.add(ElementFactory.createStartElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createEndElement(&amp;amp;quot;item&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;id&amp;amp;quot;,&amp;amp;quot;1234&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createAttribute(&amp;amp;quot;quantity&amp;amp;quot;,&amp;amp;quot;2&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;Fabulous Chair&amp;amp;quot;));&lt;br /&gt;   output.add(ElementFactory.createCharacterData(&amp;amp;quot;\n&amp;amp;quot;));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083281&quot;&gt;&lt;/a&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074022&quot;&gt;&lt;/a&gt;Adding an Input Stream to an Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1083426&quot;&gt;&lt;/a&gt;When creating an XML output stream, you might want to add an existing XML document, such as an XML file or a DOM tree, to the output stream. To do this, you must first convert the XML document to an XML input stream, then use &lt;font class=&quot;code&quot;&gt;XMLOutputStream.add(XMLInputStream)&lt;/font&gt; method to add the input stream to the output stream. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1083440&quot;&gt;&lt;/a&gt;The following example first shows a method called getInputStream() that creates an XML input stream from an XML file and then how to use the method to add the created input stream to an output stream:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083501&quot;&gt;&lt;/a&gt;  /**&lt;br /&gt;   * Helper method to get a handle on a stream.&lt;br /&gt;   * Takes in a name and returns a stream.  This&lt;br /&gt;   * method uses the InputStreamFactory to create an&lt;br /&gt;   * instance of an XMLInputStream&lt;br /&gt;   * @param name The file to parse&lt;br /&gt;   * @return XMLInputStream the stream to parse&lt;br /&gt;   */&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083511&quot;&gt;&lt;/a&gt;  public XMLInputStream getInputStream(String name)&lt;br /&gt;    throws XMLStreamException, FileNotFoundException&lt;br /&gt;  {&lt;br /&gt;    XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;br /&gt;    XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;br /&gt;    return stream;&lt;br /&gt;  }&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083474&quot;&gt;&lt;/a&gt;....&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083485&quot;&gt;&lt;/a&gt;   // create an input stream from each XML file argument then add it to the output&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1083487&quot;&gt;&lt;/a&gt;   for (int i=0; i &amp;amp;lt; args.length; i++)&lt;br /&gt;   //&lt;br /&gt;   // Get an input stream and add it to the output stream&lt;br /&gt;   //&lt;br /&gt;   output.add(printer.getInputStream(args[i]));&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1083477&quot;&gt;&lt;/a&gt;Printing an Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1086118&quot;&gt;&lt;/a&gt;Use the &lt;font class=&quot;code&quot;&gt;XMLOutputStream.flush()&lt;/font&gt; method to print out the XML output stream to whatever object you created it from. For example, if you created an XML output stream from a &lt;font class=&quot;code&quot;&gt;PrintWriter&lt;/font&gt; object, then the &lt;font class=&quot;code&quot;&gt;flush()&lt;/font&gt; method prints the stream to the standard output. &lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1089878&quot;&gt;&lt;/a&gt;&lt;strong&gt;Note: &lt;/strong&gt;If you are writing to an XMLOutputStream based on a DOM tree, you must execute the &lt;font class=&quot;code&quot;&gt;flush()&lt;/font&gt; method before you can manipulate the DOM.&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1086121&quot;&gt;&lt;/a&gt;The following example shows how to print an output stream:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1086124&quot;&gt;&lt;/a&gt;    //&lt;br /&gt;    // Print the results to the screen&lt;br /&gt;    //&lt;br /&gt;    output.flush();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;head2&quot;&gt;&lt;a name=&quot;1074024&quot;&gt;&lt;/a&gt;Closing the Output Stream&lt;/p&gt;&lt;p&gt;&lt;a name=&quot;1077787&quot;&gt;&lt;/a&gt;It is good programming practice to explicitly close the XML output stream when you are finished with it. To close an output stream, use the &lt;font class=&quot;code&quot;&gt;XMLOutputStream.close()&lt;/font&gt; method, as shown in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;font face=&quot;Courier&quot; color=&quot;#000000&quot;&gt;&lt;a name=&quot;1077805&quot;&gt;&lt;/a&gt;// close the output stream&lt;br /&gt;output.close();&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893383/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893383/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 28 Dec 2005 02:39:50 +0800</pubDate><guid isPermaLink="false">4017235@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/4017235.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893383/1235476</fs:itemid></item><item><title>Parsing an XML Document with XML Streaming API</title><link>http://sdlyi.bokee.com/4015615.html</link><description>&lt;!--StartFragment --&gt;&amp;amp;nbsp;&lt;P class=head1&gt;Parsing an XML Document: Typical Steps&lt;/P&gt;&lt;P&gt;&lt;A name=1073319&gt;&lt;/A&gt;The following procedure describes the typical steps for using the WebLogic XML Streaming API to parse and manipulate an XML document. &lt;/P&gt;&lt;P&gt;&lt;A name=1087014&gt;&lt;/A&gt;The first two steps are required. The next steps you take depend on how you want to process the XML file. &lt;/P&gt;&lt;OL type=1&gt;&lt;P&gt;&lt;/P&gt;&lt;LI value=1&gt;&lt;A name=1073628&gt;&lt;/A&gt;Import the &lt;FONT class=code&gt;weblogic.xml.stream.*&lt;/FONT&gt; classes. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=2&gt;&lt;A name=1088941&gt;&lt;/A&gt;Get an XML stream of events from an XML file, a DOM tree, or a set of SAX events. You can also filter the XML stream to get only certain types of events, names of specific elements, and so on. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073967&quot;&gt;&quot;Getting an XML Input Stream&quot; on page&amp;amp;nbsp;4-7&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=3&gt;&lt;A name=1073653&gt;&lt;/A&gt;Iterate over the stream, returning generic &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; types. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073268&quot;&gt;&quot;Iterating Over the Stream&quot; on page&amp;amp;nbsp;4-10&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=4&gt;&lt;A name=1076268&gt;&lt;/A&gt;For each generic &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; type, determine the specific event type. Event types include the start of an XML document, the end of an element, an entity reference, and so on. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076314&quot;&gt;&quot;Determining the Specific XMLEvent Type&quot; on page&amp;amp;nbsp;4-11&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=5&gt;&lt;A name=1073762&gt;&lt;/A&gt;Get the attributes of an element. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073269&quot;&gt;&quot;Getting the Attributes of an Element&quot; on page&amp;amp;nbsp;4-15&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=6&gt;&lt;A name=1073749&gt;&lt;/A&gt;Position the stream by skipping over event, skipping to a particular event, and so on. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076241&quot;&gt;&quot;Positioning the Stream&quot; on page&amp;amp;nbsp;4-16&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=7&gt;&lt;A name=1073813&gt;&lt;/A&gt;Get the children of an element. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073282&quot;&gt;&quot;Getting a Substream&quot; on page&amp;amp;nbsp;4-17&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=8&gt;&lt;A name=1073879&gt;&lt;/A&gt;Close the stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1087407&quot;&gt;&quot;Closing the Input Stream&quot; on page&amp;amp;nbsp;4-19&lt;/A&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;P class=head2&gt;&lt;A name=1073356&gt;&lt;/A&gt;Example of Parsing an XML Document&lt;/P&gt;&lt;P&gt;&lt;A name=1074073&gt;&lt;/A&gt;The following program shows an example of using the XML Streaming API to parse an XML document. &lt;/P&gt;&lt;P&gt;&lt;A name=1085248&gt;&lt;/A&gt;The program takes a single parameter, an XML file, that it converts into an XML input stream. It then iterates over the stream, determining the type of each event, such as the start of an XML element, the end of the XML document, and so on. The program prints out information for three types of events: start elements, end elements, and the character data that forms the body of an element. The program does nothing when it encounters the other types of events, such as comments or start of the XML document.&lt;/P&gt;&lt;P&gt;&lt;A name=1085321&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;The code in bold font is described in detail in the sections following the example.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083562&gt;&lt;/A&gt;package examples.xml.stream;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083564&gt;&lt;/A&gt;import weblogic.xml.stream.Attribute;&lt;BR&gt;import weblogic.xml.stream.AttributeIterator;&lt;BR&gt;import weblogic.xml.stream.ChangePrefixMapping;&lt;BR&gt;import weblogic.xml.stream.CharacterData;&lt;BR&gt;import weblogic.xml.stream.Comment;&lt;BR&gt;import weblogic.xml.stream.XMLEvent;&lt;BR&gt;import weblogic.xml.stream.EndDocument;&lt;BR&gt;import weblogic.xml.stream.EndElement;&lt;BR&gt;import weblogic.xml.stream.EntityReference;&lt;BR&gt;import weblogic.xml.stream.ProcessingInstruction;&lt;BR&gt;import weblogic.xml.stream.Space;&lt;BR&gt;import weblogic.xml.stream.StartDocument;&lt;BR&gt;import weblogic.xml.stream.StartPrefixMapping;&lt;BR&gt;import weblogic.xml.stream.StartElement;&lt;BR&gt;import weblogic.xml.stream.EndPrefixMapping;&lt;BR&gt;import weblogic.xml.stream.XMLInputStream;&lt;BR&gt;import weblogic.xml.stream.XMLInputStreamFactory;&lt;BR&gt;import weblogic.xml.stream.XMLName;&lt;BR&gt;import weblogic.xml.stream.XMLStreamException;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083584&gt;&lt;/A&gt;import java.io.FileInputStream;&lt;BR&gt;import java.io.FileNotFoundException;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083587&gt;&lt;/A&gt;public class ComplexParse {&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1084136&gt;&lt;/A&gt; /**&lt;BR&gt; * Helper method to get a handle on a stream.&lt;BR&gt; * Takes in a name and returns a stream. This&lt;BR&gt; * method usese the InputStreamFactory to create an&lt;BR&gt; * instance of an XMLInputStream&lt;BR&gt; * @param name The file to parse&lt;BR&gt; * @return XMLInputStream the stream to parse&lt;BR&gt; */&lt;BR&gt; public XMLInputStream getStream(String name)&lt;BR&gt; throws XMLStreamException, FileNotFoundException&lt;BR&gt; {&lt;BR&gt; &lt;STRONG&gt;&lt;FONT class=code&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt; XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt; return stream;&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1087729&gt;&lt;/A&gt; /**&lt;BR&gt; * Determines the type of event, such as the start&lt;BR&gt; * of an element, end of a document, and so on. If the&lt;BR&gt; * event is of type START_ELEMENT, END_ELEMENT, or&lt;BR&gt; * CHARACTER_DATA, the method prints out appropriate info;&lt;BR&gt; * otherwise, it does nothing.&lt;BR&gt; * @param event The XML event that has been parsed&lt;BR&gt; */&lt;BR&gt; public void parse(XMLEvent event)&lt;BR&gt; throws XMLStreamException&lt;BR&gt; {&lt;BR&gt; &lt;STRONG&gt;&lt;FONT class=code&gt;switch(event.getType()) {&lt;BR&gt; case XMLEvent.START_ELEMENT:&lt;BR&gt; StartElement startElement = (StartElement) event;&lt;BR&gt; System.out.print(&quot;&amp;amp;lt;&quot; + startElement.getName().getQualifiedName() );&lt;BR&gt; AttributeIterator attributes = startElement.getAttributesAndNamespaces();&lt;BR&gt; while(attributes.hasNext()){&lt;BR&gt; Attribute attribute = attributes.next();&lt;BR&gt; System.out.print(&quot; &quot; + attribute.getName().getQualifiedName() + &lt;BR&gt; &quot;=&amp;amp;apos;&quot; + attribute.getValue() + &quot;&amp;amp;apos;&quot;);&lt;BR&gt; }&lt;BR&gt; System.out.print(&quot;&amp;amp;gt;&quot;);&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.END_ELEMENT:&lt;BR&gt; System.out.print(&quot;&amp;amp;lt;/&quot; + event.getName().getQualifiedName() +&quot;&amp;amp;gt;&quot;);&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.SPACE:&lt;BR&gt; case XMLEvent.CHARACTER_DATA:&lt;BR&gt; CharacterData characterData = (CharacterData) event;&lt;BR&gt; System.out.print(characterData.getContent());&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.COMMENT:&lt;BR&gt; // Print comment&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.PROCESSING_INSTRUCTION:&lt;BR&gt; // Print ProcessingInstruction&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.START_DOCUMENT:&lt;BR&gt; // Print StartDocument&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.END_DOCUMENT:&lt;BR&gt; // Print EndDocument&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.START_PREFIX_MAPPING:&lt;BR&gt; // Print StartPrefixMapping&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.END_PREFIX_MAPPING:&lt;BR&gt; // Print EndPrefixMapping&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.CHANGE_PREFIX_MAPPING:&lt;BR&gt; // Print ChangePrefixMapping&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.ENTITY_REFERENCE:&lt;BR&gt; // Print EntityReference&lt;BR&gt; break;&lt;BR&gt; case XMLEvent.NULL_ELEMENT:&lt;BR&gt; throw new XMLStreamException(&quot;Attempt to write a null event.&quot;);&lt;BR&gt; default:&lt;BR&gt; throw new XMLStreamException(&quot;Attempt to write unknown event&lt;BR&gt; [&quot;+event.getType()+&quot;]&quot;);&lt;BR&gt; }&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt; }&lt;BR&gt; /**&lt;BR&gt; * Helper method to iterate over a stream&lt;BR&gt; * @param name The file to parse&lt;BR&gt; */&lt;BR&gt; public void parse(XMLInputStream stream)&lt;BR&gt; throws XMLStreamException&lt;BR&gt; {&lt;BR&gt; &lt;STRONG&gt;&lt;FONT class=code&gt;while(stream.hasNext()) {&lt;BR&gt; XMLEvent event = stream.next();&lt;BR&gt; parse(event);&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt; }&lt;BR&gt; &lt;FONT class=code&gt;stream.close();&lt;BR&gt;&lt;/FONT&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083853&gt;&lt;/A&gt; /** Main method. Takes a single argument: an XML file&lt;BR&gt; * that will be converted into an XML input stream.&lt;BR&gt; */&lt;BR&gt; public static void main(String args[])&lt;BR&gt; throws Exception&lt;BR&gt; {&lt;BR&gt; ComplexParse complexParse= new ComplexParse();&lt;BR&gt; complexParse.parse(complexParse.getStream(args[0]));&lt;BR&gt; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1073967&gt;&lt;/A&gt;Getting an XML Input Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1073968&gt;&lt;/A&gt;You can use the XML Streaming API to convert a variety of objects, such as XML files, DOM trees, or SAX events, into a stream of events. &lt;/P&gt;&lt;P&gt;&lt;A name=1074407&gt;&lt;/A&gt;The following example shows how to create a stream of events from an XML file:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1073478&gt;&lt;/A&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1073506&gt;&lt;/A&gt;First you create a new instance of the &lt;FONT class=code&gt;XMLInputStreamFactory&lt;/FONT&gt;, then use the factory to create a new &lt;FONT class=code&gt;XMLInputStream&lt;/FONT&gt; from the XML file referred to in the &lt;FONT class=code&gt;name&lt;/FONT&gt; variable. &lt;/P&gt;&lt;P&gt;&lt;A name=1074425&gt;&lt;/A&gt;The following example shows how to create a stream from a DOM tree:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089176&gt;&lt;/A&gt;DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;BR&gt;dbf.setValidating(false);&lt;BR&gt;dbf.setNamespaceAware(true);&lt;BR&gt;DocumentBuilder db = dbf.newDocumentBuilder();&lt;BR&gt;Document doc = db.parse(new java.io.File(file));&lt;BR&gt;XMLInputStream stream = XMLInputStreamFactory.newInstance().newInputStream(doc);&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head3&gt;&lt;A name=1087149&gt;&lt;/A&gt;Getting a Buffered XML Input Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1087162&gt;&lt;/A&gt;After you finish iterating over an &lt;FONT class=code&gt;XMLInputStream&lt;/FONT&gt; object, you cannot access the stream again. If, however, you need to process the stream again, such as send it to another application or iterate over it again in some other way, use a &lt;FONT class=code&gt;BufferedXMLInputStream&lt;/FONT&gt; object rather than a plain &lt;FONT class=code&gt;XMlInputStream&lt;/FONT&gt; object. &lt;/P&gt;&lt;P&gt;&lt;A name=1087401&gt;&lt;/A&gt;Use the &lt;FONT class=code&gt;newBufferedInputStream()&lt;/FONT&gt; method of the &lt;FONT class=code&gt;XMLInputStreamFactory&lt;/FONT&gt; class to create a buffered XMlL input stream, as shown in the following example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1087395&gt;&lt;/A&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt;BufferedXMLInputStream bufstream =&lt;BR&gt; factory.newBufferedInputStream(factory.newInputStream(new &lt;BR&gt; FileInputStream(name)));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1087389&gt;&lt;/A&gt;You can use the &lt;FONT class=code&gt;mark()&lt;/FONT&gt; and &lt;FONT class=code&gt;reset()&lt;/FONT&gt; methods of the &lt;FONT class=code&gt;BufferedXMLInputStream&lt;/FONT&gt; object to mark a particular spot in the stream, continue processing the stream, then reset the stream back to the marked spot. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073297&quot;&gt;Marking and Resetting a Buffered XML Input Stream&lt;/A&gt; for more information.&lt;/P&gt;&lt;P class=head3&gt;&lt;A name=1075615&gt;&lt;/A&gt;Filtering the XML Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1076481&gt;&lt;/A&gt;Filtering an XML stream refers to creating a stream that contains only specified types of events. For example, you can create a stream that contains only start elements, end elements, and the character data that make up the body of an XML element. Another example is filtering an XML stream so that only elements with a specified name appear in the stream.&lt;/P&gt;&lt;P&gt;&lt;A name=1076711&gt;&lt;/A&gt;To filter an XML stream, you specify a filter class as the second parameter to the &lt;FONT class=code&gt;XMLInputStreamFactory.newInputStream()&lt;/FONT&gt; method. You specify the events that you want in the XML stream as parameters to the filter class. The following example shows how to use the &lt;FONT class=code&gt;TypeFilter&lt;/FONT&gt; class to specify that you want only start and end XML elements and character data in the resulting XML stream:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1076726&gt;&lt;/A&gt;import weblogic.xml.stream.util.TypeFilter;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089339&gt;&lt;/A&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name), &lt;BR&gt; new TypeFilter(XMLEvent.START_ELEMENT |&lt;BR&gt; XMLEvent.END_ELEMENT |&lt;BR&gt; XMLEvent.CHARACTER_DATA));&lt;BR&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1081303&gt;&lt;/A&gt;The following table describes the filters provided by the WebLogic XML Streaming API. They are part of the &lt;FONT class=code&gt;weblogic.xml.stream.util&lt;/FONT&gt; package.&lt;/P&gt;&lt;DIV class=tblmargin&gt;&lt;P class=title&gt;&lt;/P&gt;&lt;P class=titletable&gt;&lt;A name=1076833&gt;&lt;/A&gt;Table 4-2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE cellSpacing=0 borderColorDark=#000000 cellPadding=3 borderColorLight=#ffffff border=1&gt;&lt;TBODY&gt;&lt;TR bgColor=#cccccc&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1076839&gt;&lt;/A&gt;&lt;STRONG&gt;Name of Filter&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1076841&gt;&lt;/A&gt;&lt;STRONG&gt;Description&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1076843&gt;&lt;/A&gt;&lt;STRONG&gt;Sample Usage&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076845&gt;&lt;/A&gt;&lt;FONT class=code&gt;TypeFilter&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076847&gt;&lt;/A&gt;Filter an XML stream based on specified event types, such as &lt;FONT class=code&gt;XMLEvent.START_ELEMENT&lt;/FONT&gt;, &lt;FONT class=code&gt;XMLEvent.END_ELEMENT&lt;/FONT&gt;, and so on. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1076314&quot;&gt;&quot;Determining the Specific XMLEvent Type&quot; on page&amp;amp;nbsp;4-11&lt;/A&gt; for a full list of event types.&lt;/P&gt;&lt;P class=table&gt;&lt;A name=1089340&gt;&lt;/A&gt;TypeFilter takes an integer bitmask as input; you OR the values to create this bitmask, as shown in the sample.&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076849&gt;&lt;/A&gt;&lt;FONT class=code&gt;new TypeFilter (XMLEvent.START_ELEMENT |&lt;BR&gt;XMLEvent.END_ELEMENT |&lt;BR&gt;XMLEvent.CHARACTER_DATA)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076851&gt;&lt;/A&gt;&lt;FONT class=code&gt;NameFilter&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076853&gt;&lt;/A&gt;Filter an XML stream based on the name of an element in the XML document.&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076855&gt;&lt;/A&gt;&lt;FONT class=code&gt;new NameFilter (&quot;Book&quot;)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076857&gt;&lt;/A&gt;&lt;FONT class=code&gt;NameSpaceFilter&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076859&gt;&lt;/A&gt;Filter an XML stream based on the specified namespace URI.&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076861&gt;&lt;/A&gt;&lt;FONT class=code&gt;new NameSpaceFilter (&quot;http://namespace.org&quot;)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076863&gt;&lt;/A&gt;&lt;FONT class=code&gt;NamespaceTypeFilter&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076865&gt;&lt;/A&gt;Filter an XML stream based on specified event types and namespace URI. This filter combines the functionality of &lt;FONT class=code&gt;TypeFilter&lt;/FONT&gt; and &lt;FONT class=code&gt;NameSpaceFilter&lt;/FONT&gt;.&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1076867&gt;&lt;/A&gt;&lt;FONT class=code&gt;new NamespaceFilter (&quot;http://namespace.org&quot;, XMLEvent.START_ELEMENT)&lt;/FONT&gt;&lt;/P&gt;&lt;P class=table&gt;&lt;A name=1089392&gt;&lt;/A&gt;&lt;BR&gt;&lt;/P&gt;&lt;P class=table&gt;&lt;A name=1089393&gt;&lt;/A&gt;The example returns a stream where all start elements have the specified namespace.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P class=head3&gt;&lt;A name=1076679&gt;&lt;/A&gt;Creating a Custom Filter&lt;/P&gt;&lt;P&gt;&lt;A name=1088958&gt;&lt;/A&gt;You can also create your own filter if the ones included in the API do not meet your needs.&lt;/P&gt;&lt;OL type=1&gt;&lt;P&gt;&lt;/P&gt;&lt;LI value=1&gt;&lt;A name=1077094&gt;&lt;/A&gt;Create a class that implements the &lt;FONT class=code&gt;ElementFilter&lt;/FONT&gt; interface and contains a method called &lt;FONT class=code&gt;accept(XMLEvent)&lt;/FONT&gt;. This method tells the &lt;FONT class=code&gt;XMLInputStreamFactory.newInputStream()&lt;/FONT&gt; method whether to add a particular event to the stream or not, as shown in the following example: &lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1076610&gt;&lt;/A&gt;package my.filters;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089476&gt;&lt;/A&gt;import weblogic.xml.stream.XMLName;&lt;BR&gt;import weblogic.xml.stream.ElementFilter;&lt;BR&gt;import weblogic.xml.stream.events.NullEvent;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089475&gt;&lt;/A&gt;public class SuperDooperFilter implements ElementFilter {&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1076627&gt;&lt;/A&gt; protected String name;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1076629&gt;&lt;/A&gt; public SuperDooperFilter(String name)&lt;BR&gt; {&lt;BR&gt; this.name = name;&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1076680&gt;&lt;/A&gt; public boolean accept(XMLEvent e) {&lt;BR&gt; if (name.equals(e.getName().getLocalName()))&lt;BR&gt; return true;&lt;BR&gt; return false;&lt;BR&gt; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=2&gt;&lt;A name=1077139&gt;&lt;/A&gt;In your XML application, be sure to import the new filter class: &lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1077224&gt;&lt;/A&gt;import my.filters.SuperDooperFilter&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=3&gt;&lt;A name=1077253&gt;&lt;/A&gt;Specify the filter as the second parameter to the &lt;FONT class=code&gt;newInputStream()&lt;/FONT&gt; method, passing to the filter class the types of events you want to appear in the XML stream in whatever format required by your filter class:&lt;/LI&gt;&lt;/OL&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1077305&gt;&lt;/A&gt;XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt;XMLInputStream stream = factory.newInputStream(new FileInputStream(name), &lt;BR&gt; new SuperDooperFilter(param));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1077063&gt;&lt;/A&gt;&lt;/P&gt;&lt;P class=head2&gt;&lt;A name=1073268&gt;&lt;/A&gt;Iterating Over the Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1074449&gt;&lt;/A&gt;Once you have a stream of events, the next step is to methodically step through it using the &lt;FONT class=code&gt;XMLInputStream.next()&lt;/FONT&gt; and &lt;FONT class=code&gt;XMLInputStream.hasNext()&lt;/FONT&gt; methods, as shown in the following example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1074689&gt;&lt;/A&gt; while(stream.hasNext()) {&lt;BR&gt; XMLEvent event = stream.next();&lt;BR&gt; System.out.print(event);&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1076314&gt;&lt;/A&gt;Determining the Specific XMLEvent Type&lt;/P&gt;&lt;P&gt;&lt;A name=1074771&gt;&lt;/A&gt;The &lt;FONT class=code&gt;XMLInputStream.next()&lt;/FONT&gt; method returns an object of type &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt;. &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; has subinterfaces that further classify what this event might be, such as the start of the XML document, the end of an element, an entity reference, and so on. The &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; interface also contains corresponding fields, or constants, as well as a set of methods that you can use to identify the actual event. The following diagram shows the hierarchy of the &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; interface and its subinterfaces:&lt;IMG height=365 hspace=0 src=&quot;http://e-docs.bea.com/wls/docs70/xml/wwimages/xml_streama.gif&quot; width=456 align=middle border=0&gt; &lt;/P&gt;&lt;P&gt;&lt;A name=1076192&gt;&lt;/A&gt;The following table lists the subclasses and fields of the &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; class that you can use to identify a particular event while parsing the XML stream.&lt;/P&gt;&lt;DIV class=tblmargin&gt;&lt;P class=title&gt;&lt;/P&gt;&lt;P class=titletable&gt;&lt;A name=1074787&gt;&lt;/A&gt;Table 4-3 Subclasses and Fields of the XMLEvent Class&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE cellSpacing=0 borderColorDark=#000000 cellPadding=3 borderColorLight=#ffffff border=1&gt;&lt;TBODY&gt;&lt;TR bgColor=#cccccc&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1074791&gt;&lt;/A&gt;&lt;STRONG&gt;XMLEvent Subclass&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1074793&gt;&lt;/A&gt;&lt;STRONG&gt;Field of the XMLEvent Class used to Identify Subclass&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1089528&gt;&lt;/A&gt;&lt;STRONG&gt;Method used to Identify Subclass&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1074878&gt;&lt;/A&gt;&lt;STRONG&gt;Description of the Subclass Event&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074795&gt;&lt;/A&gt;ChangePrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074797&gt;&lt;/A&gt;CHANGE_PREFIX_MAPPING&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089530&gt;&lt;/A&gt;isChangePrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074880&gt;&lt;/A&gt;Signals that a prefix mapping has changed from an old namespace to a new namespace.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074799&gt;&lt;/A&gt;CharacterData&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074801&gt;&lt;/A&gt;CHARACTER_DATA&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089532&gt;&lt;/A&gt;isCharacterData&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074882&gt;&lt;/A&gt;Signals that the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object contains the character data from the body of the element.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074803&gt;&lt;/A&gt;Comment&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074805&gt;&lt;/A&gt;COMMENT&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089534&gt;&lt;/A&gt;isComment&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074884&gt;&lt;/A&gt;Signals that the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object contains an XML comment.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074807&gt;&lt;/A&gt;EndDocument&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074809&gt;&lt;/A&gt;END_DOCUMENT&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089536&gt;&lt;/A&gt;isEndDocument&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074886&gt;&lt;/A&gt;Signals the end of the XML document.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074811&gt;&lt;/A&gt;EndElement&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074813&gt;&lt;/A&gt;END_ELEMENT&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089538&gt;&lt;/A&gt;isEndElement&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074888&gt;&lt;/A&gt;Signals the end of an element in the XML document.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074815&gt;&lt;/A&gt;EndPrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074817&gt;&lt;/A&gt;END_PREFIX_MAPPING&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089540&gt;&lt;/A&gt;isEndPrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074890&gt;&lt;/A&gt;Signals that a prefix mapping has gone out of scope.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074819&gt;&lt;/A&gt;EntityReference&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074821&gt;&lt;/A&gt;ENTITY_REFERENCE&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089542&gt;&lt;/A&gt;isEntityReference&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074892&gt;&lt;/A&gt;Signals that the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object contains an entity reference.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074823&gt;&lt;/A&gt;ProcessingInstruction&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074825&gt;&lt;/A&gt;PROCESSING_INSTRUCTION&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089544&gt;&lt;/A&gt;isProcessingInstruction&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074894&gt;&lt;/A&gt;Signals that the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object contains a processing instruction.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074984&gt;&lt;/A&gt;Space&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074986&gt;&lt;/A&gt;SPACE&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089546&gt;&lt;/A&gt;isSpace&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074988&gt;&lt;/A&gt;Signals that the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object contains whitespace.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074827&gt;&lt;/A&gt;StartDocument&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074829&gt;&lt;/A&gt;START_DOCUMENT&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089548&gt;&lt;/A&gt;isStartDocument&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074896&gt;&lt;/A&gt;Signals the start of an XML document.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074831&gt;&lt;/A&gt;StartElement&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074833&gt;&lt;/A&gt;START_ELEMENT&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089550&gt;&lt;/A&gt;isStartElement&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074898&gt;&lt;/A&gt;Signals the start of a element in the XML document.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074835&gt;&lt;/A&gt;StartPrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074837&gt;&lt;/A&gt;START_PREFIX_MAPPING&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1089552&gt;&lt;/A&gt;isStartPrefixMapping&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1074900&gt;&lt;/A&gt;Signals that a prefix mapping has started its scope.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A name=1075105&gt;&lt;/A&gt;The following example shows how to use the Java &lt;FONT class=code&gt;case&lt;/FONT&gt; statement to determine the particular type of event that was returned by the &lt;FONT class=code&gt;XMLInputStream.next()&lt;/FONT&gt; method. For simplicity, the example simply prints that an event has been found; later sections show further processing of the event.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079685&gt;&lt;/A&gt; switch(event.getType()) {&lt;BR&gt; case XMLEvent.START_ELEMENT:&lt;BR&gt; // Start of an element&lt;BR&gt; System.out.println (&quot;Start Element\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079690&gt;&lt;/A&gt; case XMLEvent.END_ELEMENT:&lt;BR&gt; // End of an element&lt;BR&gt; System.out.println (&quot;End Element\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079694&gt;&lt;/A&gt; case XMLEvent.PROCESSING_INSTRUCTION:&lt;BR&gt; // Processing Instruction&lt;BR&gt; System.out.println (&quot;Processing instruction\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079698&gt;&lt;/A&gt; case XMLEvent.SPACE:&lt;BR&gt; // Whitespace&lt;BR&gt; System.out.println (&quot;White space\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079702&gt;&lt;/A&gt; case XMLEvent.CHARACTER_DATA:&lt;BR&gt; // Character data&lt;BR&gt; System.out.println (&quot;Character data\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079706&gt;&lt;/A&gt; case XMLEvent.COMMENT:&lt;BR&gt; // Comment&lt;BR&gt; System.out.println (&quot;Comment\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079710&gt;&lt;/A&gt; case XMLEvent.START_DOCUMENT:&lt;BR&gt; // Start of the XML document&lt;BR&gt; System.out.println (&quot;Start Document\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079714&gt;&lt;/A&gt; case XMLEvent.END_DOCUMENT:&lt;BR&gt; // End of the XML Document&lt;BR&gt; System.out.println (&quot;End Document\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079718&gt;&lt;/A&gt; case XMLEvent.START_PREFIX_MAPPING:&lt;BR&gt; // The start of a prefix mapping scope&lt;BR&gt; System.out.println (&quot;Start prefix mapping\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079722&gt;&lt;/A&gt; case XMLEvent.END_PREFIX_MAPPING:&lt;BR&gt; // The end of a prefix mapping scope&lt;BR&gt; System.out.println (&quot;End prefix mapping\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079726&gt;&lt;/A&gt; case XMLEvent.CHANGE_PREFIX_MAPPING:&lt;BR&gt; // Prefix mapping has changed namespaces&lt;BR&gt; System.out.println (&quot;Change prefix mapping\n&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079730&gt;&lt;/A&gt; case XMLEvent.ENTITY_REFERENCE:&lt;BR&gt; // An entity reference&lt;BR&gt; System.out.println (&quot;Entity reference\n&quot;);&lt;BR&gt; break;&lt;BR&gt; default:&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1079735&gt;&lt;/A&gt; throw new XMLStreamException(&quot;Attempt to parse unknown event &lt;BR&gt; [&quot; + event.getType() + &quot;]&quot;);&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1073269&gt;&lt;/A&gt;Getting the Attributes of an Element&lt;/P&gt;&lt;P&gt;&lt;A name=1075434&gt;&lt;/A&gt;To get the attributes of an element in an XML document, you must first cast the &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; object that was returned by the &lt;FONT class=code&gt;XMLInputStream.next()&lt;/FONT&gt; method to a &lt;FONT class=code&gt;StartElement&lt;/FONT&gt; object. &lt;/P&gt;&lt;P&gt;&lt;A name=1075451&gt;&lt;/A&gt;Because you do not know how many attributes an element might have, you must first create an &lt;FONT class=code&gt;AttributeIterator&lt;/FONT&gt; object to contain the entire list of attributes, and then iterate over the list until there are no more attributes. The following example describes how to do this as part of the &lt;FONT class=code&gt;START_ELEMENT&lt;/FONT&gt; case of the &lt;FONT class=code&gt;switch&lt;/FONT&gt; statement shown in &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1073268&quot;&gt;&quot;Iterating Over the Stream&quot; on page&amp;amp;nbsp;4-10&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1075494&gt;&lt;/A&gt;case XMLEvent.START_ELEMENT:&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1075495&gt;&lt;/A&gt; StartElement startElement = (StartElement) event;&lt;BR&gt; System.out.print(&quot;&amp;amp;lt;&quot; + startElement.getName().getQualifiedName() );&lt;BR&gt; AttributeIterator attributes = startElement.getAttributesAndNamespaces();&lt;BR&gt; while(attributes.hasNext()){&lt;BR&gt; Attribute attribute = attributes.next();&lt;BR&gt; System.out.print(&quot; &quot; + attribute.getName().getQualifiedName() + &lt;BR&gt; &quot;=&amp;amp;apos;&quot; + attribute.getValue() + &quot;&amp;amp;apos;&quot;);&lt;BR&gt; }&lt;BR&gt; System.out.print(&quot;&amp;amp;gt;&quot;);&lt;BR&gt; break;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1076239&gt;&lt;/A&gt;The example first creates a &lt;FONT class=code&gt;StartElement&lt;/FONT&gt; object by casting the returned &lt;FONT class=code&gt;XMLEvent&lt;/FONT&gt; to &lt;FONT class=code&gt;StartElement&lt;/FONT&gt;. It then creates an &lt;FONT class=code&gt;AttributeIterator&lt;/FONT&gt; object using the method &lt;FONT class=code&gt;StartElement.getAttributesAndNamespaces()&lt;/FONT&gt;, and iterates over the attributes using the &lt;FONT class=code&gt;AttributeIterator.hasNext()&lt;/FONT&gt; method. For each &lt;FONT class=code&gt;Attribute&lt;/FONT&gt;, it uses the &lt;FONT class=code&gt;Attributes.getName().getQualifiedName()&lt;/FONT&gt; and &lt;FONT class=code&gt;Attribute.getValue()&lt;/FONT&gt; methods to return the name and value of the attribute.&lt;/P&gt;&lt;P&gt;&lt;A name=1089634&gt;&lt;/A&gt;You can also use the &lt;FONT class=code&gt;getNamespace()&lt;/FONT&gt; and &lt;FONT class=code&gt;getAttributes()&lt;/FONT&gt; methods to return just the namespaces or attributes on their own.&lt;/P&gt;&lt;P class=head2&gt;&lt;A name=1076241&gt;&lt;/A&gt;Positioning the Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1080059&gt;&lt;/A&gt;The following table describes the methods of the &lt;FONT class=code&gt;XMLInputStream&lt;/FONT&gt; interface that you can use to skip ahead to specific locations in the stream.&lt;/P&gt;&lt;DIV class=tblmargin&gt;&lt;P class=title&gt;&lt;/P&gt;&lt;P class=titletable&gt;&lt;A name=1080222&gt;&lt;/A&gt;Table 4-4 Methods Used to Position the Input Stream&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE cellSpacing=0 borderColorDark=#000000 cellPadding=3 borderColorLight=#ffffff border=1&gt;&lt;TBODY&gt;&lt;TR bgColor=#cccccc&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1080224&gt;&lt;/A&gt;&lt;STRONG&gt;Method of XMLInputStream &lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;TH vAlign=top align=left&gt;&lt;B&gt;&lt;P class=table&gt;&lt;A name=1080357&gt;&lt;/A&gt;&lt;STRONG&gt;Description&lt;/STRONG&gt;&lt;/P&gt;&lt;/B&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080226&gt;&lt;/A&gt;&lt;FONT class=code&gt;skip()&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080359&gt;&lt;/A&gt;Positions the input stream to the next stream event. &lt;/P&gt;&lt;P class=table&gt;&lt;A name=1080723&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;The next event might not necessarily be an actual element in the XML file; for example, it could be a comment or white space.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080228&gt;&lt;/A&gt;&lt;FONT class=code&gt;skip(int)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080361&gt;&lt;/A&gt;Positions the input stream to the next event of this type. &lt;/P&gt;&lt;P class=table&gt;&lt;A name=1080669&gt;&lt;/A&gt;Examples of event types are &lt;FONT class=code&gt;XMLEvent.START_ELEMENT&lt;/FONT&gt; and &lt;FONT class=code&gt;XMLEvent.END_DOCUMENT&lt;/FONT&gt;. Refer to &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074787&quot;&gt;Table&amp;amp;nbsp;4-3&lt;/A&gt; for the full list of event types.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080230&gt;&lt;/A&gt;&lt;FONT class=code&gt;skip(XMLName)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080363&gt;&lt;/A&gt;Positions the input stream to the next event of this name. &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080232&gt;&lt;/A&gt;&lt;FONT class=code&gt;skip(XMLName, int)&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080365&gt;&lt;/A&gt;Positions the input stream to the next event of this name and type.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080234&gt;&lt;/A&gt;&lt;FONT class=code&gt;skipElement()&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080367&gt;&lt;/A&gt;Skips to the next element (does not skip to the sub-elements of the current element).&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080236&gt;&lt;/A&gt;&lt;FONT class=code&gt;peek()&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD vAlign=top align=left&gt;&lt;P class=table&gt;&lt;A name=1080369&gt;&lt;/A&gt;Checks the next event without actually reading it from the stream.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A name=1081171&gt;&lt;/A&gt;The following example shows how you can modify the basic code for iterating over an input stream to skip over the character data in the body of an XML element:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1081188&gt;&lt;/A&gt; while(stream.hasNext()) {&lt;BR&gt; XMLEvent peek = stream.peek();&lt;BR&gt; if (peek.getType() == XMLEvent.CHARACTER_DATA ) {&lt;BR&gt; stream.skip();&lt;BR&gt; continue;&lt;BR&gt; }&lt;BR&gt; XMLEvent event = stream.next();&lt;BR&gt; parse(event);&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1081173&gt;&lt;/A&gt;The example shows how to use the &lt;FONT class=code&gt;XMLInputStream.peek()&lt;/FONT&gt; method to determine the next event on the stream. If the type of event is &lt;FONT class=code&gt;XMLEvent.CHARACTER_DATA&lt;/FONT&gt;, then skip the event and go to the next one.&lt;/P&gt;&lt;P class=head2&gt;&lt;A name=1073282&gt;&lt;/A&gt;Getting a Substream&lt;/P&gt;&lt;P&gt;&lt;A name=1077868&gt;&lt;/A&gt;Use the &lt;FONT class=code&gt;XMLInputStream.getSubStream()&lt;/FONT&gt; method to get a copy of the next element, including all its subelements. The &lt;FONT class=code&gt;getSubstream()&lt;/FONT&gt; method returns an &lt;FONT class=code&gt;XMLInputStream&lt;/FONT&gt; object. Your position in the parent stream (or the stream from which you called &lt;FONT class=code&gt;getSubStream()&lt;/FONT&gt;) does not move. In the parent stream, if you want to skip the element you just got with &lt;FONT class=code&gt;getSubStream()&lt;/FONT&gt;, use the &lt;FONT class=code&gt;skipElement()&lt;/FONT&gt; method.&lt;/P&gt;&lt;P&gt;&lt;A name=1086474&gt;&lt;/A&gt;The &lt;FONT class=code&gt;getSubStream()&lt;/FONT&gt; method keeps a count of the &lt;FONT class=code&gt;START_ELEMENT&lt;/FONT&gt; and &lt;FONT class=code&gt;END_ELEMENT&lt;/FONT&gt; events it encounters, and as soon as the number is equal (or in other words, as soon as it finds the complete next element) it stops and returns the resulting substream as an &lt;FONT class=code&gt;XMLInputStream&lt;/FONT&gt; object. &lt;/P&gt;&lt;P&gt;&lt;A name=1082264&gt;&lt;/A&gt;For example, assume that you are using the XML Streaming API to parse the following XML document, but you are only interested in the substream delineated by the &lt;FONT class=code&gt;&amp;amp;lt;content&amp;amp;gt;&lt;/FONT&gt; and &lt;FONT class=code&gt;&amp;amp;lt;/content&amp;amp;gt;&lt;/FONT&gt; tags:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1081424&gt;&lt;/A&gt;&amp;amp;lt;book&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;title&amp;amp;gt;The History of the World&amp;amp;lt;/title&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;author&amp;amp;gt;Juliet Shackell&amp;amp;lt;/author&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;publisher&amp;amp;gt;CrazyDays Publishing&amp;amp;lt;/publisher&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;content&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;chapter title=&amp;amp;apos;Just a Speck of Dust&amp;amp;apos;&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;synopsis&amp;amp;gt;The world as a speck of dust&amp;amp;lt;/synopsis&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;para&amp;amp;gt;Once the world was just a speck of dust...&amp;amp;lt;/para&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;/chapter&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;chapter title=&amp;amp;apos;Life Appears&amp;amp;apos;&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;synopsis&amp;amp;gt;Move over dust, here comes life.&amp;amp;lt;/synopsis&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;para&amp;amp;gt;Happily, the dust got a companion: life...&amp;amp;lt;/para&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;/chapter&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;/content&amp;amp;gt;&lt;BR&gt;&amp;amp;lt;/book&amp;amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1081636&gt;&lt;/A&gt;The following code fragment shows how you can skip to the &lt;FONT class=code&gt;&amp;amp;lt;content&amp;amp;gt;&lt;/FONT&gt; start element tag, get the substream, and parse it using a separate &lt;FONT class=code&gt;ComplexParse&lt;/FONT&gt; object:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086555&gt;&lt;/A&gt; if (stream.skip( ElementFactory.createXMLName(&quot;content&quot;)))&lt;BR&gt; {&lt;BR&gt; ComplexParse complexParse = new ComplexParse();&lt;BR&gt; complexParse.parse(stream.getSubStream());&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1086519&gt;&lt;/A&gt;When you call this method on the previous XML document, you get the following output:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086695&gt;&lt;/A&gt;&amp;amp;lt;content&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;chapter title=&amp;amp;apos;Just a Speck of Dust&amp;amp;apos;&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;synopsis&amp;amp;gt;The world as a speck of dust&amp;amp;lt;/synopsis&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;para&amp;amp;gt;Once the world was just a speck of dust...&amp;amp;lt;/para&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;/chapter&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;chapter title=&amp;amp;apos;Life Appears&amp;amp;apos;&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;synopsis&amp;amp;gt;Move over dust, here comes life.&amp;amp;lt;/synopsis&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;para&amp;amp;gt;Happily, the dust got a companion: life...&amp;amp;lt;/para&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;/chapter&amp;amp;gt;&lt;BR&gt;&amp;amp;lt;/content&amp;amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1073297&gt;&lt;/A&gt;Marking and Resetting a Buffered XML Input Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1087423&gt;&lt;/A&gt;If you are using a &lt;FONT class=code&gt;BufferedXMLInputStream&lt;/FONT&gt; object, you can use the &lt;FONT class=code&gt;mark()&lt;/FONT&gt; and &lt;FONT class=code&gt;reset()&lt;/FONT&gt; methods to mark the stream at a particular spot, process the stream, and then subsequently reset the stream back to the marked spot. These methods are useful if you want to further manipulate the stream after initially iterating over it. &lt;/P&gt;&lt;P&gt;&lt;A name=1089716&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;If you read a buffered stream without marking it, you cannot access what you&amp;amp;apos;ve just read. In other words, just because the stream is buffered, it does not automatically mean you can reread it. You must mark it first.&lt;/P&gt;&lt;P&gt;&lt;A name=1087453&gt;&lt;/A&gt;The following example shows a typical use of the &lt;FONT class=code&gt;BufferedXMLInputStream&lt;/FONT&gt; object:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089707&gt;&lt;/A&gt; XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt; BufferedXMLInputStream bufstream =&lt;BR&gt; factory.newBufferedInputStream(factory.newInputStream(new &lt;BR&gt; FileInputStream(name)));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089697&gt;&lt;/A&gt; // mark the start of the stream&lt;BR&gt; bufstream.mark();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1087486&gt;&lt;/A&gt; // process it locally&lt;BR&gt; bufferedParse.parse(bufstream);&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1087490&gt;&lt;/A&gt; // reset the stream to the mark&lt;BR&gt; bufstream.reset();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1087494&gt;&lt;/A&gt; // send stream off to another application&lt;BR&gt; ComplexParse complexParse = new ComplexParse();&lt;BR&gt; complexParse.parse(bufstream);&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1087407&gt;&lt;/A&gt;Closing the Input Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1086524&gt;&lt;/A&gt;It is good programming practice to explicitly close the XML input stream when you are finished with it. To close an input stream, use the &lt;FONT class=code&gt;XMLInputStream.close()&lt;/FONT&gt; method, as shown in the following example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1077834&gt;&lt;/A&gt;// close the input stream&lt;BR&gt;input.close();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;amp;nbsp;&lt;/P&gt;&lt;HR noShade&gt;&lt;P class=head1&gt;&lt;A name=1074012&gt;&lt;/A&gt;Generating a New XML Document: Typical Steps&lt;/P&gt;&lt;P&gt;&lt;A name=1087063&gt;&lt;/A&gt;The following procedure describes the typical steps for using the WebLogic XML Streaming API to generate a new XML document. &lt;/P&gt;&lt;P&gt;&lt;A name=1087064&gt;&lt;/A&gt;The first two steps are required. The next steps you take depend on how you want to generate the XML file. &lt;/P&gt;&lt;OL type=1&gt;&lt;P&gt;&lt;/P&gt;&lt;LI value=1&gt;&lt;A name=1089026&gt;&lt;/A&gt;Import the &lt;FONT class=code&gt;weblogic.xml.stream.*&lt;/FONT&gt; classes. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=2&gt;&lt;A name=1089029&gt;&lt;/A&gt;Create an XML output stream to which to write the XML document. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074017&quot;&gt;&quot;Creating an XML Output Stream&quot; on page&amp;amp;nbsp;4-22&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=3&gt;&lt;A name=1077527&gt;&lt;/A&gt;Add events to the XML output stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074020&quot;&gt;&quot;Adding Elements to the Output Stream&quot; on page&amp;amp;nbsp;4-23&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=4&gt;&lt;A name=1077540&gt;&lt;/A&gt;Add attributes to the XML output stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074021&quot;&gt;&quot;Adding Attributes to an Element on the Output Stream&quot; on page&amp;amp;nbsp;4-24&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=5&gt;&lt;A name=1077555&gt;&lt;/A&gt;Add an input stream to the output stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074022&quot;&gt;&quot;Adding an Input Stream to an Output Stream&quot; on page&amp;amp;nbsp;4-25&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=6&gt;&lt;A name=1077568&gt;&lt;/A&gt;Print the output stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1083477&quot;&gt;&quot;Printing an Output Stream&quot; on page&amp;amp;nbsp;4-26&lt;/A&gt;. &lt;P&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI value=7&gt;&lt;A name=1077475&gt;&lt;/A&gt;Close the output stream. See &lt;A href=&quot;http://e-docs.bea.com/wls/docs70/xml/xml_stream.html#1074024&quot;&gt;&quot;Closing the Output Stream&quot; on page&amp;amp;nbsp;4-26&lt;/A&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;P class=head2&gt;&lt;A name=1074015&gt;&lt;/A&gt;Example of Generating an XML Document&lt;/P&gt;&lt;P&gt;&lt;A name=1077595&gt;&lt;/A&gt;The following program shows an example of using the XML Streaming API to generate an XML document. &lt;/P&gt;&lt;P&gt;&lt;A name=1086110&gt;&lt;/A&gt;The program first creates an output stream based on a &lt;FONT class=code&gt;PrintWriter&lt;/FONT&gt; object, then adds elements to the output stream to create a simple XML purchase order, described in the comments of the program. The program also shows how to add an input stream based on a separate XML file to the output stream.&lt;/P&gt;&lt;P&gt;&lt;A name=1085396&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;The topics following the example describe it in more detail.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085406&gt;&lt;/A&gt;package examples.xml.stream;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085408&gt;&lt;/A&gt;import weblogic.xml.stream.XMLInputStream;&lt;BR&gt;import weblogic.xml.stream.XMLOutputStream;&lt;BR&gt;import weblogic.xml.stream.XMLInputStreamFactory;&lt;BR&gt;import weblogic.xml.stream.XMLName;&lt;BR&gt;import weblogic.xml.stream.XMLEvent;&lt;BR&gt;import weblogic.xml.stream.StartElement;&lt;BR&gt;import weblogic.xml.stream.EndElement;&lt;BR&gt;import weblogic.xml.stream.Attribute;&lt;BR&gt;import weblogic.xml.stream.ElementFactory;&lt;BR&gt;import weblogic.xml.stream.XMLStreamException;&lt;BR&gt;import weblogic.xml.stream.XMLOutputStreamFactory;&lt;BR&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085420&gt;&lt;/A&gt;import java.io.FileInputStream;&lt;BR&gt;import java.io.FileNotFoundException;&lt;BR&gt;import java.io.PrintWriter;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085424&gt;&lt;/A&gt;/**&lt;BR&gt; * Program that prints out a very simple purchase order that looks&lt;BR&gt; * like the following:&lt;BR&gt; *&lt;BR&gt; * &amp;amp;lt;purchase_order&amp;amp;gt;&lt;BR&gt; * &amp;amp;lt;name&amp;amp;gt;Juliet Shackell&amp;amp;lt;/name&amp;amp;gt;&lt;BR&gt; * &amp;amp;lt;item id=&quot;1234&quot; quantity=&quot;2&quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;BR&gt; * &amp;amp;lt;!-- this is a comment--&amp;amp;gt;&lt;BR&gt; * &amp;amp;lt;another_file&amp;amp;gt;&lt;BR&gt; * This comes from another file called &quot;another_file.xml&quot;&lt;BR&gt; * &amp;amp;lt;/another_file&amp;amp;gt;&lt;BR&gt; * &amp;amp;lt;/purchase_order&amp;amp;gt;&lt;BR&gt; *&lt;BR&gt; * In the preceding XML file, the &amp;amp;lt;another_file&amp;amp;gt; element is actually another&lt;BR&gt; * XML file that is passed as an argument to the program, converted into an&lt;BR&gt; * XMLInputStream, then added to the output stream.&lt;BR&gt; */&lt;BR&gt;public class PrintPurchaseOrder {&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085444&gt;&lt;/A&gt; /**&lt;BR&gt; * Helper method to get a handle on a stream.&lt;BR&gt; * Takes in a name and returns a stream. This&lt;BR&gt; * method uses the InputStreamFactory to create an&lt;BR&gt; * instance of an XMLInputStream&lt;BR&gt; * @param name The file to parse&lt;BR&gt; * @return XMLInputStream the stream to parse&lt;BR&gt; */&lt;BR&gt; public XMLInputStream getInputStream(String name)&lt;BR&gt; throws XMLStreamException, FileNotFoundException&lt;BR&gt; {&lt;BR&gt; XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt; XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;BR&gt; return stream;&lt;BR&gt; }&lt;BR&gt; public static void main(String args[])&lt;BR&gt; throws Exception&lt;BR&gt; {&lt;BR&gt; PrintPurchaseOrder printer = new PrintPurchaseOrder();&lt;BR&gt; //&lt;BR&gt; // Create an output stream.&lt;BR&gt; //&lt;BR&gt; XMLOutputStreamFactory factory = XMLOutputStreamFactory.newInstance();&lt;BR&gt; XMLOutputStream output = factory.newOutputStream(new &lt;BR&gt; PrintWriter(System.out,true));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085518&gt;&lt;/A&gt; // add the &amp;amp;lt;purchase_order&amp;amp;gt; root element&lt;BR&gt; output.add(ElementFactory.createStartElement(&quot;purchase_order&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085523&gt;&lt;/A&gt; // add the &amp;amp;lt;name&amp;amp;gt; element&lt;BR&gt; output.add(ElementFactory.createStartElement(&quot;name&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;Juliet Shackell&quot;));&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;name&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085531&gt;&lt;/A&gt; // add the &amp;amp;lt;item&amp;amp;gt; element along with the id and quantity attributes&lt;BR&gt; output.add(ElementFactory.createStartElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;id&quot;,&quot;1234&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;quantity&quot;,&quot;2&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;Fabulous Chair&quot;));&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085541&gt;&lt;/A&gt; // add a comment&lt;BR&gt; output.add(&quot;&amp;amp;lt;!-- this is a comment--&amp;amp;gt;&quot;);&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086017&gt;&lt;/A&gt; // create an input stream from each XML file argument then add it to the output&lt;BR&gt; for (int i=0; i &amp;amp;lt; args.length; i++)&lt;BR&gt; //&lt;BR&gt; // Get an input stream and add it to the output stream&lt;BR&gt; //&lt;BR&gt; output.add(printer.getInputStream(args[i]));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086067&gt;&lt;/A&gt; // Finally, end the root &quot;purchase_order&quot; element&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;purchase_order&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;)); &lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086095&gt;&lt;/A&gt; //&lt;BR&gt; // Print the results to the screen&lt;BR&gt; //&lt;BR&gt; output.flush();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1085595&gt;&lt;/A&gt; // Close the output streams&lt;BR&gt; output.close();&lt;BR&gt; }&lt;BR&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1086906&gt;&lt;/A&gt;The preceding program produces the following output:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086918&gt;&lt;/A&gt;&amp;amp;lt;purchase_order&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;name&amp;amp;gt;Juliet Shackell&amp;amp;lt;/name&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;item id=&quot;1234&quot; quantity=&quot;2&quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;!-- this is a comment--&amp;amp;gt;&lt;BR&gt; &amp;amp;lt;another_file&amp;amp;gt;&lt;BR&gt; This is from another file.&lt;BR&gt; &amp;amp;lt;/another_file&amp;amp;gt;&lt;BR&gt;&amp;amp;lt;/purchase_order&amp;amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1074017&gt;&lt;/A&gt;Creating an XML Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1077631&gt;&lt;/A&gt;One of the first steps in generating an XML document using the Weblogic XML Streaming API is to create an output stream which holds the document as it is being built. Creating an XML output stream is similar to creating an input stream: you first create an instance of the &lt;FONT class=code&gt;XMLOutputStreamFactory&lt;/FONT&gt; and then create an output stream with the &lt;FONT class=code&gt;XMLOutputStreamFactory.newOutputStream()&lt;/FONT&gt; method, as shown in the following example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1077652&gt;&lt;/A&gt; XMLOutputStreamFactory factory = XMLOutputStreamFactory.newInstance();&lt;BR&gt; XMLOutputStream output = factory.newOutputStream(new&lt;BR&gt; PrintWriter(System.out,true));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1077660&gt;&lt;/A&gt;The following example shows how to create an &lt;FONT class=code&gt;XMLOutputStream&lt;/FONT&gt; based on a DOM tree:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1089842&gt;&lt;/A&gt; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;BR&gt; dbf.setValidating(false);&lt;BR&gt; dbf.setNamespaceAware(true);&lt;BR&gt; Document doc = dbf.newDocumentBuilder().newDocument();&lt;BR&gt; XMLOutputStream out =&lt;BR&gt; XMLOutputStreamFactory.newInstance().newOutputStream(doc);&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1089798&gt;&lt;/A&gt;You can use the &lt;FONT class=code&gt;XMLOutputStreamFactory.newOutputStream()&lt;/FONT&gt; method to create an output stream based on the following four Java objects, depending on what the final form of the XML document will be (such as a file on the operating system, a DOM tree, and so on):&lt;/P&gt;&lt;UL type=square&gt;&lt;P&gt;&lt;A name=1077691&gt;&lt;/A&gt;&lt;/P&gt;&lt;LI type=square&gt;&lt;FONT class=code&gt;java.io.OutputStream&lt;/FONT&gt; &lt;P&gt;&lt;A name=1077692&gt;&lt;/A&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI type=square&gt;&lt;FONT class=code&gt;java.io.Writer&lt;/FONT&gt; &lt;P&gt;&lt;A name=1077694&gt;&lt;/A&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI type=square&gt;&lt;FONT class=code&gt;org.xml.sax.ContentHandler&lt;/FONT&gt; &lt;P&gt;&lt;A name=1077685&gt;&lt;/A&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI type=square&gt;&lt;FONT class=code&gt;org.w3c.dom.Document&lt;/FONT&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;P class=head2&gt;&lt;A name=1074020&gt;&lt;/A&gt;Adding Elements to the Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1077739&gt;&lt;/A&gt;Use the &lt;FONT class=code&gt;XMLOutputStream.add(XMLEvent)&lt;/FONT&gt; method to add elements to the output stream. Use the &lt;FONT class=code&gt;ElementFactory&lt;/FONT&gt; to create the particular element.&lt;/P&gt;&lt;P&gt;&lt;A name=1082954&gt;&lt;/A&gt;The &lt;FONT class=code&gt;ElementFactory&lt;/FONT&gt; interface includes methods to create each type of element; the general format is &lt;FONT class=code&gt;ElementFactory.create&lt;/FONT&gt;&lt;EM&gt;XXX&lt;/EM&gt;&lt;FONT class=code&gt;()&lt;/FONT&gt; where &lt;EM&gt;&lt;FONT class=code&gt;XXX&lt;/FONT&gt;&lt;/EM&gt; refers to the particular element, such as &lt;FONT class=code&gt;createStartElement()&lt;/FONT&gt;, &lt;FONT class=code&gt;createCharacterData()&lt;/FONT&gt;, and so on. You can create most elements by passing the name as a &lt;FONT class=code&gt;String&lt;/FONT&gt; or as an &lt;FONT class=code&gt;XMLName&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&lt;A name=1089870&gt;&lt;/A&gt;&lt;STRONG&gt;Warning: &lt;/STRONG&gt;The &lt;FONT class=code&gt;XMLOutputStream&lt;/FONT&gt; does not validate your XML.&lt;/P&gt;&lt;P&gt;&lt;A name=1082972&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;Each time you create a start element, you must explicitly also create an end element at some point. The same rule applies to creating a start document. &lt;/P&gt;&lt;P&gt;&lt;A name=1082967&gt;&lt;/A&gt;For example, assume you want to create the following snippet of XML:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083032&gt;&lt;/A&gt;&amp;amp;lt;name&amp;amp;gt;Georgina Shackell Green&amp;amp;lt;/name&amp;amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1083328&gt;&lt;/A&gt;The Java code to add this element to an output stream is as follows:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083339&gt;&lt;/A&gt; output.add(ElementFactory.createStartElement(&quot;name&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;Georgina Shackell Green&quot;));&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;name&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1083330&gt;&lt;/A&gt;The final &lt;FONT class=code&gt;createCharacterData()&lt;/FONT&gt; method adds a newline character to the output stream. This is optional, but useful if you want to create human-readable XML.&lt;/P&gt;&lt;P class=head2&gt;&lt;A name=1074021&gt;&lt;/A&gt;Adding Attributes to an Element on the Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1083083&gt;&lt;/A&gt;Use the &lt;FONT class=code&gt;XMLOutputStream.add(Attribute)&lt;/FONT&gt; to add attributes to an element you have just created. Use the &lt;FONT class=code&gt;ElementFactory.createAttribute()&lt;/FONT&gt; method to create a particular attribute. &lt;/P&gt;&lt;P&gt;&lt;A name=1083086&gt;&lt;/A&gt;For example, assume you want to create the following snippet of XML:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083087&gt;&lt;/A&gt;&amp;amp;lt;item id=&quot;1234&quot; quantity=&quot;2&quot;&amp;amp;gt;Fabulous Chair&amp;amp;lt;/item&amp;amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1083395&gt;&lt;/A&gt;The Java code to add this element to an output stream is as follows:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083396&gt;&lt;/A&gt; output.add(ElementFactory.createStartElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;id&quot;,&quot;1234&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;quantity&quot;,&quot;2&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;Fabulous Chair&quot;));&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A name=1083223&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;Be sure you add attributes to an element &lt;EM&gt;after&lt;/EM&gt; you create the start element but &lt;EM&gt;before&lt;/EM&gt; you create the corresponding end element. Otherwise, although your code will compile successfully, you will get a runtime error when you try to run the program. For example, the following code returns an error because the attributes are added to the &lt;FONT class=code&gt;&amp;amp;lt;item&amp;amp;gt;&lt;/FONT&gt; element &lt;EM&gt;after&lt;/EM&gt; the element has been explicitly ended:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083413&gt;&lt;/A&gt; output.add(ElementFactory.createStartElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createEndElement(&quot;item&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;id&quot;,&quot;1234&quot;));&lt;BR&gt; output.add(ElementFactory.createAttribute(&quot;quantity&quot;,&quot;2&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;Fabulous Chair&quot;));&lt;BR&gt; output.add(ElementFactory.createCharacterData(&quot;\n&quot;));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083281&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1074022&gt;&lt;/A&gt;Adding an Input Stream to an Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1083426&gt;&lt;/A&gt;When creating an XML output stream, you might want to add an existing XML document, such as an XML file or a DOM tree, to the output stream. To do this, you must first convert the XML document to an XML input stream, then use &lt;FONT class=code&gt;XMLOutputStream.add(XMLInputStream)&lt;/FONT&gt; method to add the input stream to the output stream. &lt;/P&gt;&lt;P&gt;&lt;A name=1083440&gt;&lt;/A&gt;The following example first shows a method called getInputStream() that creates an XML input stream from an XML file and then how to use the method to add the created input stream to an output stream:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083501&gt;&lt;/A&gt; /**&lt;BR&gt; * Helper method to get a handle on a stream.&lt;BR&gt; * Takes in a name and returns a stream. This&lt;BR&gt; * method uses the InputStreamFactory to create an&lt;BR&gt; * instance of an XMLInputStream&lt;BR&gt; * @param name The file to parse&lt;BR&gt; * @return XMLInputStream the stream to parse&lt;BR&gt; */&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083511&gt;&lt;/A&gt; public XMLInputStream getInputStream(String name)&lt;BR&gt; throws XMLStreamException, FileNotFoundException&lt;BR&gt; {&lt;BR&gt; XMLInputStreamFactory factory = XMLInputStreamFactory.newInstance();&lt;BR&gt; XMLInputStream stream = factory.newInputStream(new FileInputStream(name));&lt;BR&gt; return stream;&lt;BR&gt; }&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083474&gt;&lt;/A&gt;....&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083485&gt;&lt;/A&gt; // create an input stream from each XML file argument then add it to the output&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1083487&gt;&lt;/A&gt; for (int i=0; i &amp;amp;lt; args.length; i++)&lt;BR&gt; //&lt;BR&gt; // Get an input stream and add it to the output stream&lt;BR&gt; //&lt;BR&gt; output.add(printer.getInputStream(args[i]));&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1083477&gt;&lt;/A&gt;Printing an Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1086118&gt;&lt;/A&gt;Use the &lt;FONT class=code&gt;XMLOutputStream.flush()&lt;/FONT&gt; method to print out the XML output stream to whatever object you created it from. For example, if you created an XML output stream from a &lt;FONT class=code&gt;PrintWriter&lt;/FONT&gt; object, then the &lt;FONT class=code&gt;flush()&lt;/FONT&gt; method prints the stream to the standard output. &lt;/P&gt;&lt;P&gt;&lt;A name=1089878&gt;&lt;/A&gt;&lt;STRONG&gt;Note: &lt;/STRONG&gt;If you are writing to an XMLOutputStream based on a DOM tree, you must execute the &lt;FONT class=code&gt;flush()&lt;/FONT&gt; method before you can manipulate the DOM.&lt;/P&gt;&lt;P&gt;&lt;A name=1086121&gt;&lt;/A&gt;The following example shows how to print an output stream:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1086124&gt;&lt;/A&gt; //&lt;BR&gt; // Print the results to the screen&lt;BR&gt; //&lt;BR&gt; output.flush();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P class=head2&gt;&lt;A name=1074024&gt;&lt;/A&gt;Closing the Output Stream&lt;/P&gt;&lt;P&gt;&lt;A name=1077787&gt;&lt;/A&gt;It is good programming practice to explicitly close the XML output stream when you are finished with it. To close an output stream, use the &lt;FONT class=code&gt;XMLOutputStream.close()&lt;/FONT&gt; method, as shown in the following example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;FONT face=Courier color=#000000&gt;&lt;A name=1077805&gt;&lt;/A&gt;// close the output stream&lt;BR&gt;output.close();&lt;/FONT&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;!-- BACK TO TOP --&gt;&lt;P&gt;&lt;/P&gt;&lt;p class=&quot;fswww1&quot;&gt;&lt;a href=&quot;http://www1.feedsky.com/r/l/feedsky/sdlyi/397893384/art01.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; ismap=&quot;ismap&quot; src=&quot;http://www1.feedsky.com/r/i/feedsky/sdlyi/397893384/art01.gif&quot; onerror=&quot;this.style.display='none'&quot; /&gt;&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 28 Dec 2005 00:08:20 +0800</pubDate><guid isPermaLink="false">4015615@http://sdlyi.bokee.com/</guid><dc:subject>Struts</dc:subject><fs:srclink>http://sdlyi.bokee.com/4015615.html</fs:srclink><fs:srcfeed>http://sdlyi.bokee.com/rss2.xml</fs:srcfeed><fs:itemid>feedsky/sdlyi/~1228587/397893384/1235476</fs:itemid></item></channel></rss>
