﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-weidagang2046的专栏-文章分类-XML</title><link>http://www.blogjava.net/weidagang2046/category/1128.html</link><description>物格而后知致</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 21:23:02 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 21:23:02 GMT</pubDate><ttl>60</ttl><item><title>XQuery动态创建XML Element</title><link>http://www.blogjava.net/weidagang2046/articles/97321.html</link><dc:creator>weidagang2046</dc:creator><author>weidagang2046</author><pubDate>Thu, 01 Feb 2007 09:06:00 GMT</pubDate><guid>http://www.blogjava.net/weidagang2046/articles/97321.html</guid><wfw:comment>http://www.blogjava.net/weidagang2046/comments/97321.html</wfw:comment><comments>http://www.blogjava.net/weidagang2046/articles/97321.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weidagang2046/comments/commentRss/97321.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weidagang2046/services/trackbacks/97321.html</trackback:ping><description><![CDATA[
		<font face="Courier New">
				<font size="2">
						<span class="c9Y6TC">
								<font color="#0000ff">element</font>
						</span> {<span class="c4ZSSG"><font color="#800080">"tag"</font></span>} {<span class="c9Y6TC"><font color="#0000ff">attribute</font></span> {<span class="c4ZSSG"><font color="#800080">"id"</font></span>}{<span class="c4ZSSG"><font color="#800080">"1"</font></span>}, <span class="c4ZSSG"><font color="#800080">"content"</font></span>} <br /><br />result:<br /><br />&lt;tag id="1"&gt;content&lt;/tag&gt;</font>
		</font>
<img src ="http://www.blogjava.net/weidagang2046/aggbug/97321.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weidagang2046/" target="_blank">weidagang2046</a> 2007-02-01 17:06 <a href="http://www.blogjava.net/weidagang2046/articles/97321.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A Simple XQuery Case</title><link>http://www.blogjava.net/weidagang2046/articles/93688.html</link><dc:creator>weidagang2046</dc:creator><author>weidagang2046</author><pubDate>Sat, 13 Jan 2007 16:11:00 GMT</pubDate><guid>http://www.blogjava.net/weidagang2046/articles/93688.html</guid><wfw:comment>http://www.blogjava.net/weidagang2046/comments/93688.html</wfw:comment><comments>http://www.blogjava.net/weidagang2046/articles/93688.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weidagang2046/comments/commentRss/93688.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weidagang2046/services/trackbacks/93688.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;?</span>
				<span style="COLOR: #ff00ff">xml version="1.0" encoding="ISO-8859-1"</span>
				<span style="COLOR: #0000ff">?&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">bookstore</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">book </span>
				<span style="COLOR: #ff0000">category</span>
				<span style="COLOR: #0000ff">="COOKING"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">  <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">title </span>
				<span style="COLOR: #ff0000">lang</span>
				<span style="COLOR: #0000ff">="en"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Everyday Italian</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">title</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Giada De Laurentiis</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">2005</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">30.00</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">book</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">book </span>
				<span style="COLOR: #ff0000">category</span>
				<span style="COLOR: #0000ff">="CHILDREN"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">title </span>
				<span style="COLOR: #ff0000">lang</span>
				<span style="COLOR: #0000ff">="en"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Harry Potter</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">title</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">J K. Rowling</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">2005</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">29.99</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">book</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">book </span>
				<span style="COLOR: #ff0000">category</span>
				<span style="COLOR: #0000ff">="WEB"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">title </span>
				<span style="COLOR: #ff0000">lang</span>
				<span style="COLOR: #0000ff">="en"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">XQuery Kick Start</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">title</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">James McGovern</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Per Bothner</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Kurt Cagle</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">James Linn</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Vaidyanathan Nagarajan</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">2003</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">49.99</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">book</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">book </span>
				<span style="COLOR: #ff0000">category</span>
				<span style="COLOR: #0000ff">="WEB"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">title </span>
				<span style="COLOR: #ff0000">lang</span>
				<span style="COLOR: #0000ff">="en"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Learning XML</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">title</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Erik T. Ray</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">author</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">2003</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">year</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">39.95</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">price</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">book</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">bookstore</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>book.xml<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">names</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />for $x in doc("book.xml")/bookstore/book<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />where $x/price &gt; 30<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />return </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">{$x/title/text()}</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">names</span><span style="COLOR: #0000ff">&gt;</span></div>query.xq<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">names</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">XQuery Kick Start</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">Learning XML</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">names</span><span style="COLOR: #0000ff">&gt;</span></div>names.xml<img src ="http://www.blogjava.net/weidagang2046/aggbug/93688.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weidagang2046/" target="_blank">weidagang2046</a> 2007-01-14 00:11 <a href="http://www.blogjava.net/weidagang2046/articles/93688.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SAX Parser</title><link>http://www.blogjava.net/weidagang2046/articles/3677.html</link><dc:creator>weidagang2046</dc:creator><author>weidagang2046</author><pubDate>Sun, 24 Apr 2005 02:04:00 GMT</pubDate><guid>http://www.blogjava.net/weidagang2046/articles/3677.html</guid><wfw:comment>http://www.blogjava.net/weidagang2046/comments/3677.html</wfw:comment><comments>http://www.blogjava.net/weidagang2046/articles/3677.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weidagang2046/comments/commentRss/3677.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weidagang2046/services/trackbacks/3677.html</trackback:ping><description><![CDATA[<FONT size=2>作者<BR>2003 年 3 月 </FONT>
<BLOCKQUOTE><FONT size=2>读取和操纵 XML 文件的标准方法是 DOM（“文档对象模型”）。遗憾的是，这种方法需要读取整个文件并将它存储到树结构中，因而效率不高、缓慢，并且会过度使用资源。</FONT></BLOCKQUOTE>
<P><A name=0><SPAN class=atitle2><FONT size=2>什么是 SAX</FONT></SPAN></A><BR><FONT size=2>读取和操纵 XML 文件的标准方法是 DOM（“文档对象模型”）。遗憾的是，这种方法需要读取整个文件并将它存储到树结构中，因而效率不高、缓慢，并且会过度使用资源。</FONT></P>
<P><FONT size=2>一种替代方法是使用 Simple API for XML 或 SAX。SAX 允许正在读取文档时处理该文档，这避免了在采取操作之前需要等待存储文档的所有内容。</FONT></P>
<P><FONT size=2>SAX 是由 XML-DEV 邮件列表的成员开发的，Java 版本由 David Megginson 维护。他们的目的是提供一种更自然的方法来使用 XML，这种方法不会涉及到使用 DOM 的那种开销。</FONT></P>
<P><FONT size=2>结果是基于事件的 API。解析器将事件（譬如，元素的开始或结束）发送给处理信息的事件处理程序。然后，应用程序自己可以处理数据。虽然原始文档保持不变，但 SAX 提供了操纵数据的方法，然后会将该方法导向另一个过程或文档。</FONT></P>
<P><FONT size=2>对于 SAX，没有官方的标准；万维网（W3C）或其它官方组织不维护 SAX，但在 XML 社区中，它是一个事实上的标准。</FONT></P>
<P><A name=1><SPAN class=atitle2><FONT size=2>SAX 处理是如何工作的</FONT></SPAN></A><BR><FONT size=2>SAX 分析经过其的 XML 流，这非常象老式的自动收报机纸条。考虑以下 XML 代码片断：</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>&lt;?xml version="1.0"?&gt;
&lt;samples&gt;
&lt;server&gt;UNIX&lt;/server&gt;
&lt;monitor&gt;color&lt;/monitor&gt;
&lt;/samples&gt;
</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><FONT size=2>一般情况下，SAX 处理器分析这段代码将生成以下事件：</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>Start document
Start element (samples)
Characters (white space)
Start element (server)
Characters (UNIX)
End element (server)
Characters (white space)
Start element (monitor)
Characters (color)
End element (monitor)
Characters (white space)
End element (samples)
</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><FONT size=2>SAX API 允许开发者捕获这些事件，并对它们进行操作。</FONT></P>
<P><FONT size=2>SAX 处理涉及以下几步：</FONT></P>
<OL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dw="http://www.ibm.com/developerworks/">
<LI><FONT size=2>创建事件处理程序。 </FONT>
<LI><FONT size=2>创建 SAX 解析器。 </FONT>
<LI><FONT size=2>将事件处理程序分配给解析器。 </FONT>
<LI><FONT size=2>对文档进行解析，将每个事件发送给处理程序。 </FONT></LI></OL>
<P><A name=2><SPAN class=atitle2><FONT size=2>在SAX与DOM之间，如何选择</FONT></SPAN></A><BR><FONT size=2>选择 DOM 还是 SAX，这取决于几个因素：</FONT></P>
<OL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dw="http://www.ibm.com/developerworks/">
<LI><FONT size=2>应用程序的目的：如果必须对数据进行更改，并且作为 XML 将它输出，则在大多数情况下，使用 DOM。与使用 XSL 转换来完成的简单结构更改不一样，如果是对数据本身进行更改，则尤其应该使用 DOM。 </FONT>
<LI><FONT size=2>数据的数量：对于大文件，SAX 是更好的选择。 </FONT>
<LI><FONT size=2>将如何使用数据：如果实际上只使用一小部分数据，则使用 SAX 将数据抽取到应用程序中，这种方法更好些。另一方面，如果知道将需要向后引用已经处理过的信息，则 SAX 可能不是正确的选择。 </FONT>
<LI><FONT size=2>需要速度：通常，SAX 实现比 DOM 实现快。 </FONT></LI></OL>
<P><FONT size=2>记住 SAX 和 DOM 不是互斥的，这一点很重要。可以使用 DOM 来创建事件的 SAX 流，可以使用 SAX 来创建 DOM 树。事实上，大多数解析器实际常常使用 SAX 来创建 DOM 树！</FONT></P>
<P><A name=3><SPAN class=atitle2><FONT size=2>使用 JAXP 来创建解析器</FONT></SPAN></A><BR><FONT size=2>接下来我们来看一下JAXP的SAX Parser是怎么样工作的。</FONT></P>
<P><FONT size=2>首先声明 XMLReader xmlReader。然后使用 SAXParserFactory 来创建 SAXParser。正是 SAXParser 给您了 XMLReader。</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;

public class SurveyReader extends DefaultHandler
{
public SurveyReader() {
}

public static void main (String args[]) {
XMLReader xmlReader = null;
try {
SAXParserFactory spfactory =
SAXParserFactory.newInstance();
spfactory.setValidating(false);	//设置验证选项,
如果您的XML文件是有效文档的话,
就不用验证.这将提高处理速度
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();

} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
}
</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><A name=4><SPAN class=atitle2><FONT size=2>设置内容处理程序</FONT></SPAN></A><BR><FONT size=2>一旦创建了解析器，则需要将 SurveyReader 设置为内容处理程序，以便于其接收事件。</FONT></P>
<P><FONT size=2>xmlReader 的 setContentHandler() 方法完成这项工作。</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>...
xmlReader = saxParser.getXMLReader();

xmlReader.setContentHandler(new SurveyReader());

} catch (Exception e) {
...
</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><FONT size=2>当然，对于内容处理程序，这不是唯一的选项。</FONT></P>
<P><A name=5><SPAN class=atitle2><FONT size=2>解析 InputSource</FONT></SPAN></A><BR><FONT size=2>为了对文件进行实际地解析，需要 InputSource。这个 SAX 类封装了所有将要处理的数据，所以不必担心它来自哪里。</FONT></P>
<P><FONT size=2>现在，准备对文件进行实际解析。应用程序将封装在 InputSource 中的文件传递给 parse()，然后应用程序会继续运行。</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>...

import org.xml.sax.InputSource;

...
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new SurveyReader());

InputSource source = new InputSource("surveys.xml");
xmlReader.parse(source);


} catch (Exception e) {
...
</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><FONT size=2>可以编译和运行该程序，但这时应该什么也没有发生，因为应用程序还没有定义任何事件。</FONT></P>
<P><A name=6><SPAN class=atitle2><FONT size=2>创建 ErrorHandler</FONT></SPAN></A><BR><FONT size=2>当然总会有可能在试图进行解析时，数据有问题。在这样的情况下，有一个处理程序来处理错误和内容将是有帮助的。</FONT></P>
<P><FONT size=2>就如同创建内容处理程序一样，可以创建出错处理程序。通常，将作为 ErrorHandler 的单独实例来创建它，但为了简化该示例，出错处理正是包含在 SurveyResults 中。由于该类继承了 DefaultHandler 且没有扩展 ContentHandler，所以这种双重用法是可能的。</FONT></P>
<P><FONT size=2>需要关注的事件有三个：警告、错误和致命错误。</FONT></P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE>
<FONT size=2>...

import org.xml.sax.SAXParseException;


public class SurveyReader extends DefaultHandler
{

public SurveyReader() {
}
public void error (SAXParseException e) {
System.out.println("Error parsing the file: "+e.getMessage());
}
public void warning (SAXParseException e) {
System.out.println("Problem parsing the file: "+e.getMessage());
}
public void fatalError (SAXParseException e) {
System.out.println("Error parsing the file: "+e.getMessage());
System.out.println("Cannot continue.");
System.exit(1);
}
}
....
xmlReader.setContentHandler(new SurveyReader());

xmlReader.setErrorHandler(new SurveyReader());
//设置 ErrorHandler

InputSource source = new InputSource("surveys.xml");
....

public static void main (String args[]) {
...

</FONT></CODE></PRE></TD></TR></TBODY></TABLE>
<P><A name=7><SPAN class=atitle2><FONT size=2>SAX 事件</FONT></SPAN></A><BR><FONT size=2>以下事件是常用的；它们都在 org.xml.sax 包的 HandlerBase 类中定义。</FONT></P>
<OL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dw="http://www.ibm.com/developerworks/">
<LI><FONT size=2>startDocument 表示文档开始。 </FONT>
<LI><FONT size=2>endDocument 表示文档结束。 </FONT>
<LI><FONT size=2>startElement 表示元素开始。当一对标记中的起始标记中的所有内容被处理后，解析器 激发此事件。包括了标记名和其属性。 </FONT>
<LI><FONT size=2>endElement 表示元素结束。 </FONT>
<LI><FONT size=2>characters 包含字符数据，类似于 DOM 的一个 Text 节点。 </FONT></LI></OL>
<P><FONT size=2>还有更多的 SAX 事件：</FONT></P>
<OL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dw="http://www.ibm.com/developerworks/">
<LI><FONT size=2>ignorableWhitespace 此事件类似于我们前面所讨论的无用 DOM 节点。它与 character 事件的区别，好处是:如果您不需要空格符，您可以通过忽略这个事件来忽略所有的空格符。 </FONT>
<LI><FONT size=2>warning、error 和 fatalError 这三个事件表示了解析错误。您可根据需要来响应它们。 </FONT>
<LI><FONT size=2>setDocumentLocator 这个事件允许您存储一个 SAX 的 Locator 对象。Locator 对象可以用来找出在文档中确切发生事件的地方。 </FONT></LI></OL>
<P><FONT size=2>转自：<A href="http://www-128.ibm.com/developerworks/cn/xml/x-cert/part8/">http://www-128.ibm.com/developerworks/cn/xml/x-cert/part8/</A></FONT></P><img src ="http://www.blogjava.net/weidagang2046/aggbug/3677.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weidagang2046/" target="_blank">weidagang2046</a> 2005-04-24 10:04 <a href="http://www.blogjava.net/weidagang2046/articles/3677.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Introduction to DOM</title><link>http://www.blogjava.net/weidagang2046/articles/3660.html</link><dc:creator>weidagang2046</dc:creator><author>weidagang2046</author><pubDate>Sat, 23 Apr 2005 08:20:00 GMT</pubDate><guid>http://www.blogjava.net/weidagang2046/articles/3660.html</guid><wfw:comment>http://www.blogjava.net/weidagang2046/comments/3660.html</wfw:comment><comments>http://www.blogjava.net/weidagang2046/articles/3660.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/weidagang2046/comments/commentRss/3660.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weidagang2046/services/trackbacks/3660.html</trackback:ping><description><![CDATA[<DIV>
<H2><FONT color=#666699><A name=25192></A><FONT size=2>Introduction</FONT></FONT><FONT size=2> 
<HR>
</FONT></H2></DIV><A name=pgfId-1128147></A>
<P class=Body><A name=pgfId-1128157></A><FONT size=2>This tutorial is a simple introduction to DOM. There is a more in-depth and technical coverage of the DOM API in the "Complete DOM" tutorial.</FONT></P>
<P class=Body><A name=pgfId-1140554></A><FONT size=2>As a Java programmer, once you have some XML documents, you will probably need to access the information contained in them using your Java code. Since the XML document is just a text file, you can write your own text file reader which interprets the information in the XML document in a way that your code can use. It is a very time consuming process to write such an XML document reader, and if you think about it, such code would have to be written over and over again for different programs that needed access to the information in XML documents. The W3C realized that this is the case and they created a standard way to create these "XML document readers" or XML parsers. The good news is that you don't have to write these parsers, free parsers are provided by many companies out there, including Sun, Datachannel and IBM. These parsers are written in Java too, you must use XML parsers written in Java in your Java programs.</FONT></P>
<DIV>
<H2><FONT color=#666699><A name=20882></A><FONT size=2>What is a DOM XML parser?</FONT></FONT><FONT size=2> 
<HR>
</FONT></H2></DIV><A name=pgfId-1128155></A>
<P class=Body><A name=pgfId-1128171></A><FONT size=2>A DOM XML parser is a Java program that converts your XML documents into some Java object model. Once you have parsed an XML document, it exists in the memory of you Java Virutal Machine as a bunch of objects. When you need to access or modify information stored in the XML document, you dont have to manipulate the XML document file directly, instead you must access and modify the information through these objects in memory. So the DOM XML parser creates a Java document object representaion of your XML document file. </FONT></P>
<P class=Body><A name=pgfId-1128172></A><FONT size=2>The parser also performs some simple text processing as it creates an object model of your XML document; it expands all entities used in the file and it compares the structure of the information in the XML document to a DTD (if one is used). Once the simple processing is successful, the parser creates a document object representation of your XML document file. In order to access and modify the information in this document object, you need a reference object (of some class type) in order to call methods on the document object. The W3C has also created a set of Java interfaces called the Document Object Model API, which allow you to access and modify information in a document object created by the XML parser. So instead of accessing this document object with a reference of its implementation class type, the W3C expects you to access the document object with the standard DOM Java interfaces. The document class must implement these DOM interfaces.</FONT></P>
<P class=Body><A name=pgfId-1128173></A><FONT size=2>DOM is just a set of Java interfaces which have been defined by the W3C, however, no implementations of these interfaces are provided. The XML parser writers must provide the implementations for the DOM interfaces themselves.</FONT></P>
<P class=Body><A name=pgfId-1128174></A><FONT size=2>Since XML parsers may be written for any platform and language, the W3C has not provided an implementation for the DOM interfaces, and it leaves it up to the XML parser impementor to provide a good implementation. By doing this, another advantage is that your XML documents and Java programs (that you write) are not dependent on any particular parser.</FONT></P>
<DIV>
<H2><FONT color=#666699><A name=79604></A><FONT size=2>What is DOM?</FONT></FONT><FONT size=2> 
<HR>
</FONT></H2></DIV><A name=pgfId-1128169></A>
<P class=Body><A name=pgfId-1128188></A><FONT size=2>In order for your Java programs to access the information in XML documents, the parser must read the XML files from the first layer. The parser processes the file by checking the information contained in it for validity (by using a DTD if one is used) and expanding all the entities used in the file. Then this (processed) XML document is converted into an XML document object in memory by the XML parser. This document object contains a <EM class=Bold>tree of nodes</EM> that contain the data and structure of the information contained in the XML document. This tree of nodes can be accessed and modified using the DOM API.</FONT></P>
<P class=Body><A name=pgfId-1128192></A><FONT size=2>DOM is similar to the Swing component models, like TableModel, ListModel and TreeModel. These models are simply interfaces which must be implemented by classes that contain the actual data. For example, if you wish to display information in a 2D array to a JTable, you must create a class that contains the 2D array and then have this class implement the TableModel interface. So the TableModel does not contain the data, it merely allows the JTable to access the underlying 2D data; the data exists in an instance (object) of the class that implements the model. The DOM does not contain the data, but merely allows you to access your underlying XML data from the Java programs that you write. The document object contains the data, the class (of which this document object is an instance of) also implements the appropriate DOM interfaces. The parser has the responsibility of providing the implementation classes for the interfaces and also a way to instantiate them.</FONT></P>
<P class=Body><A name=pgfId-1140401></A><FONT size=2>So the parser creates some objects, which are instances of some classes that implement certain interfaces defined in the DOM API. These objects are instantiated when the Parser reads an XML document. Now, instead of accessing these objects directly, you rely on using some Java interfaces (defined in the DOM API by the W3C) to access and manipulate these objects. These objects effectively contain the information that is in your XML document, but they only allow you to access and modify this information using the Java interfaces defined in the DOM API. So the Document Object Model is very similar to the Swing models (like TreeModel, ListModel and TableModel) which is just a set of interfaces without the implementation. This entire process is illustrated in Figure 1.</FONT></P>
<DIV><FONT size=2><IMG src="http://www.developerlife.com/domintro/file-1.jpg"> </FONT></DIV>
<P class=Body><A name=pgfId-1140402></A><FONT size=2>The good news about DOM and XML Parsers is that you don't have to implement the DOM API or write the parser. There are many companies that provide XML Parsers for different languages and they all implement the DOM interfaces. </FONT></P>
<DIV>
<H3><FONT color=#666699><A name=87329></A><FONT size=2>Overview</FONT></FONT><FONT size=2> 
<HR>
</FONT></H3></DIV><A name=pgfId-1128186></A>
<P class=Body><A name=pgfId-1140452></A><FONT size=2>The DOM API allows hierarchical access to the information in an XML document. An XML Parser converts the information in an XML document into a tree of nodes after parsing the document. DOM allows you to access this tree of nodes using the Java interfaces defined in the DOM API. The entire XML document, no matter how simple or how complicated, is converted into a tree of nodes, and all the nodes start from one root node, which is called a <EM class=Bold>document</EM> object, hence the name <EM class=Bold>Document</EM> Object Model. Once a document object tree has been created (by the XML parser, or your own code), you can access elements in that tree and you can also modify, delete and create leaves and branches by using the interfaces in the API. Figure 2 shows how information in an XML document can be represented as a tree of nodes.</FONT></P>
<DIV><FONT size=2><IMG src="http://www.developerlife.com/domintro/file-2.jpg"> </FONT></DIV>
<P class=Body><A name=pgfId-1140453></A><FONT size=2>In the document object tree, everything is a node. A node may have other nodes inside it and the node itself can hold information, like its tag-name and value and its child nodes (if any). This hierarchical organization of information is similar to a file system, where files and folders are organized hierarchically, a folder may have files in it or other folders, and everything is descended from one root folder. Similarly, a document object is descended from one node, and it may have other nodes inside it. The document object itself is a node.</FONT></P>
<P class=Body><A name=pgfId-1128233></A><FONT size=2>The DOM API defines a minimal set of (language and platform independent) interfaces for accessing and manipulating the content and structure of information stored in XML documents, in a hierarchical manner.</FONT></P>
<DIV>
<H3><FONT color=#666699><A name=67443></A><FONT size=2>API Package Names</FONT></FONT><FONT size=2> 
<HR>
</FONT></H3></DIV><A name=pgfId-1128219></A>
<P class=Body><A name=pgfId-1128242></A><FONT size=2>The interfaces for DOM are required (by the W3C) to exist in the <EM class=FM-code>org.w3c.dom</EM> package. You have to use the following include statement in your programs that use DOM: <EM class=FM-code>import org.w3c.dom.*;</EM> . The implementation for the Java interfaces in these packages are provided by the XML parser that you choose to use. The DOM interfaces are also shipped with the XML parser implementation that you use, and you have to put the implementation class files (or jar file) in your CLASSPATH.</FONT></P>
<P class=Body><A name=pgfId-1140501></A><FONT size=2>However, the code to instantiate DOM objects is dependent on the parser that you are using. Remember, DOM is just a set of interfaces, and interfaces can't be instantiated in Java; only the classes that implement these interfaces may be instantiated. With the parsers used in this book, it only takes one line of XML parser specific code to instantiate a DOM object (using some specific XML parser). Once the XML parser specific object has been instantiated (that implements the appropriate DOM interfaces), you should access these objects only through the DOM interfaces. So, except for the one line of XML parser specific code, all your other code can be completely standards based and portable. If you use the factory pattern to instantiate the objects that implement DOM interfaces, then your classes will be completely portable and won't even have that one line of parser specific code embedded in them. </FONT></P>
<DIV>
<H3><FONT color=#666699><A name=57190></A><FONT size=2>Important interfaces in the API</FONT></FONT><FONT size=2> 
<HR>
</FONT></H3></DIV><A name=pgfId-1140503></A>
<P class=Body><A name=pgfId-1140468></A><FONT size=2>An XML document object that is created by the parser (after reading a XML file (contains a tree of Node objects (i.e. instances of some Node interface implementation class). In DOM, everything is a Node. The other interfaces are provided to make things more object oriented, but you can manipulate all your information in DOM by just using the Node interface. Figure 3 shows the inheritance relationships between some of the important interfaces.</FONT></P>
<DIV><FONT size=2><IMG src="http://www.developerlife.com/domintro/file-3.jpg"> </FONT></DIV>
<P class=Body><A name=pgfId-1140469></A><FONT size=2>The root Node object of the document tree is also a Document object; Document is a subclass of Node. Every DOM object must have a root. Another important interface is the Element interface (which is a subclass of Node); the Element interface can be used to access the elements in a DOM Document object tree.</FONT></P>
<P class=Body><A name=pgfId-1131941></A><FONT size=2>The Node interface encapsulates access to a lot of information about a node, some of this information is listed in Table 1.</FONT></P>
<TABLE border=1>
<CAPTION>
<H6 class=TableTitle><A name=pgfId-1131990></A><A name=49870></A><FONT size=2>Some information that the Node interface encapsulates</FONT></H6></CAPTION>
<TBODY>
<TR>
<TH>
<P class=CellBody><A name=pgfId-1131994></A><FONT size=2>The Node interface allows you to find out the following information about a Node object</FONT></P></TH>
<TH>
<P class=CellBody><A name=pgfId-1131996></A><FONT size=2>Examples</FONT></P></TH></TR>
<TR>
<TD>
<P class=CellBody><A name=pgfId-1131998></A><FONT size=2>What is the Node's type, tag name and value?</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132000></A><FONT size=2>&lt;email&gt; xml@beanfactory.com &lt;/email&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132002></A><FONT size=2>For this email Node (and Element), the Node type is Node.ELEMENT_NODE. The tag name is email. The Node's value is "xml@beanfactory.com".</FONT></P></TD></TR>
<TR>
<TD>
<P class=CellBody><A name=pgfId-1132004></A><FONT size=2>What are the Node's children Nodes (if it has any)?</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132006></A><FONT size=2>&lt;person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132007></A><FONT size=2>&lt;name&gt; Nazmul Idris &lt;/name&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132008></A><FONT size=2>&lt;email&gt; xml@beanfactory.com &lt;/email&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132009></A><FONT size=2>&lt;/person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132011></A><FONT size=2>The person Node has two children Nodes, name and email.</FONT></P></TD></TR>
<TR>
<TD>
<P class=CellBody><A name=pgfId-1132013></A><FONT size=2>Does the Node have any children?</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132015></A><FONT size=2>&lt;addressbook&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132016></A><FONT size=2>&lt;person&gt; ... &lt;/person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132017></A><FONT size=2>&lt;person&gt; ... &lt;/person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132018></A><FONT size=2>&lt;/addressbook&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132020></A><FONT size=2>The addressbook Node has children.</FONT></P>
<P class=CellBody><A name=pgfId-1132022></A><FONT size=2>&lt;email&gt; xml@beanfactory.com &lt;/email&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132024></A><FONT size=2>The email Node does not have any children.</FONT></P></TD></TR></TBODY></TABLE>
<P class=Body><A name=pgfId-1128313></A><FONT size=2>Figure 4 illustrates a sample XML Document object tree and describes all the Node objects that are contained in it.</FONT></P>
<DIV><FONT size=2><IMG src="http://www.developerlife.com/domintro/file-4.jpg"> </FONT></DIV>
<P class=Body><A name=pgfId-1128321></A><FONT size=2>You can find out if a Node has children or not by using the <EM class=FM-code>hasChildNodes()</EM> method. Node is a simple interface and you have to make sure that you follow the rules in Table 2 when using it.</FONT></P>
<TABLE border=1>
<CAPTION>
<H6 class=TableTitle><A name=pgfId-1132042></A><FONT size=2>Rules that apply to Node objects</FONT></H6></CAPTION>
<TBODY>
<TR>
<TH>
<P class=CellBody><A name=pgfId-1132046></A><FONT size=2>Rule</FONT></P></TH>
<TH>
<P class=CellBody><A name=pgfId-1132048></A><FONT size=2>Example</FONT></P></TH></TR>
<TR>
<TD>
<P class=CellBody><A name=pgfId-1132050></A><FONT size=2>If a Node object has a value (i.e. it contains some text data) then it may or may not have children elements.</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132078></A><FONT size=2>&lt;name&gt; Nazmul Idris &lt;/name&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132079></A><FONT size=2>The name Node (and Element) does not have children elements, only data.</FONT></P></TD></TR>
<TR>
<TD>
<P class=Body><A name=pgfId-1132054></A><FONT size=2>If a Node object has children then it may or may not have a value</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132090></A><FONT size=2>&lt;person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1140539></A><FONT size=2>some data</FONT></P>
<P class=CellBody><A name=pgfId-1132091></A><FONT size=2>&lt;name&gt; Nazmul Idris &lt;/name&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132092></A><FONT size=2>&lt;email&gt; xml@beanfactory.com &lt;/email&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132093></A><FONT size=2>&lt;/person&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132094></A><FONT size=2>The person Node (and Element) may have a value as well as other child Nodes (Elements) </FONT></P></TD></TR>
<TR>
<TD>
<P class=CellBody><A name=pgfId-1132058></A><FONT size=2>A Node may also have no children or no value.</FONT></P></TD>
<TD>
<P class=CellBody><A name=pgfId-1132102></A><FONT size=2>&lt;indexmarker/&gt;</FONT></P>
<P class=CellBody><A name=pgfId-1132060></A><FONT size=2>The indexmarker Node does not have any children and neither does it contain any data. </FONT></P></TD></TR></TBODY></TABLE>
<P class=Body><A name=pgfId-1128354></A><FONT size=2>If a Node has children, then it may or may not have a value. In Figure 4, the <EM class=FM-code>person</EM> element has children Nodes and a value. The <EM class=FM-code>email</EM> and <EM class=FM-code>name</EM> Nodes don't have any children and have values. If a Node has no children, it might also contain no value (like an element with an EMPTY data storage declaration).</FONT></P>
<P class=Body><A name=pgfId-1128358></A><FONT size=2>The <EM class=FM-code>getNodeType()</EM> method returns the type of a Node; the type is just a constant int that is used to identify different types of Nodes, for example the Node.ELEMENT_NODE type identifies a Node to be an Element. You can use the <EM class=FM-code>getNodeValue()</EM> method to get the textual data stored inside a Node. </FONT></P>
<P class=Body><A name=pgfId-1132372></A><FONT size=2>The Node interface has methods that allow the traversal of a Node tree. The <EM class=FM-code>getChildNodes()</EM> method is useful for getting all the elements inside a Node. This method returns all Nodes (if they exist) in an object that is a container for Node objects; this object implements the NodeList interface. NodeList is an iterator for a list of Nodes. Figure 5 illustrates how NodeList can be used.</FONT></P>
<DIV><FONT size=2><IMG src="http://www.developerlife.com/domintro/file-5.jpg"> </FONT></DIV>
<P class=Body><A name=pgfId-1128254></A><FONT size=2>In the "Complete DOM" tutorial, I will cover the DOM API in more depth and explain what all the interfaces do and have plenty of code examples. This tutorial is a simple introduction to the idea of DOM.<BR><BR>转自：<A href="http://www.developerlife.com/domintro/default.htm">http://www.developerlife.com/domintro/default.htm</A></FONT></P><img src ="http://www.blogjava.net/weidagang2046/aggbug/3660.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weidagang2046/" target="_blank">weidagang2046</a> 2005-04-23 16:20 <a href="http://www.blogjava.net/weidagang2046/articles/3660.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用JAXB处理XML文档――先睹为快</title><link>http://www.blogjava.net/weidagang2046/articles/3650.html</link><dc:creator>weidagang2046</dc:creator><author>weidagang2046</author><pubDate>Sat, 23 Apr 2005 06:34:00 GMT</pubDate><guid>http://www.blogjava.net/weidagang2046/articles/3650.html</guid><wfw:comment>http://www.blogjava.net/weidagang2046/comments/3650.html</wfw:comment><comments>http://www.blogjava.net/weidagang2046/articles/3650.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weidagang2046/comments/commentRss/3650.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weidagang2046/services/trackbacks/3650.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: JAXB以其方便的XML数据处理能力可能会引起你的兴趣。你可能还不了解JAXB是什么，想要知道它到底有什么好处，如果这是你需要的，你才会再花时间去细细的研究它，或者你只需要使用最基本的功能。然而Sun关于JAXB的文档有80页之多。我想大部分人都没有耐心看完这样的长篇大论。本文以简短的篇幅介绍了JAXB的基本使用，算是先睹为快吧。本文附带的代码包括了JAXB1.0 early access版本和本...&nbsp;&nbsp;<a href='http://www.blogjava.net/weidagang2046/articles/3650.html'>阅读全文</a><img src ="http://www.blogjava.net/weidagang2046/aggbug/3650.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weidagang2046/" target="_blank">weidagang2046</a> 2005-04-23 14:34 <a href="http://www.blogjava.net/weidagang2046/articles/3650.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>