﻿<?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-Skynet-随笔分类-xml Related</title><link>http://www.blogjava.net/Good-Game/category/24758.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 29 May 2008 08:45:38 GMT</lastBuildDate><pubDate>Thu, 29 May 2008 08:45:38 GMT</pubDate><ttl>60</ttl><item><title>xquery 学习 (简单demo)</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/29/203834.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Thu, 29 May 2008 06:49:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/29/203834.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/203834.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/29/203834.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/203834.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/203834.html</trackback:ping><description><![CDATA[xml 数据库使用，和XQuery使用.<br />环境:<br />    1.xml数据库使用<img title="eXist" src="http://demo.exist-db.org/logo.jpg" height="35" width="90" />（参考：eXist<a href="http://exist-db.org/quickstart.html">Quick Start</a>）<br />    2.xQuery <a href="http://www.w3school.com.cn/xquery/index.asp" title="XQuery 教程">XQuery 首页</a><br />    <br />1.测试开始：<br />    进入：eXist-&gt; http://demo.exist-db.org/xmldb/db/ <table align="center" bgcolor="#666699" border="0" width="80%"><tbody><tr><th align="left" width="50%">for $x in doc("/examples2.xml")/exist:result/country

return	if ($x/population_growth&lt;-1)

	then &lt;child&gt;{data($x/name)}&lt;/child&gt;

	else &lt;adult&gt;{data($x/name)}&lt;/adult&gt;</th><th class="pages" align="right" width="50%"><br /></th></tr><tr bgcolor="#cacaca"><td colspan="2"><a href="http://demo.exist-db.org/xmldb/db/">parent collection: /db</a></td></tr><tr><td colspan="2" bgcolor="#9999cc"><dl><dd><font color="navy">&lt;</font><font color="navy">child</font><font color="navy">
              &gt;
            </font><font color="black">Bosnia and Herzegovina</font><font color="navy">
              &lt;/
              child
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#cacaca"><dl><dd><font color="navy">&lt;</font><font color="navy">adult</font><font color="navy">
              &gt;
            </font><font color="black">Czech Republic</font><font color="navy">
              &lt;/
              adult
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#9999cc"><dl><dd><font color="navy">&lt;</font><font color="navy">child</font><font color="navy">
              &gt;
            </font><font color="black">Estonia</font><font color="navy">
              &lt;/
              child
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#cacaca"><dl><dd><font color="navy">&lt;</font><font color="navy">child</font><font color="navy">
              &gt;
            </font><font color="black">Faroe Islands</font><font color="navy">
              &lt;/
              child
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#9999cc"><dl><dd><font color="navy">&lt;</font><font color="navy">adult</font><font color="navy">
              &gt;
            </font><font color="black">Hungary</font><font color="navy">
              &lt;/
              adult
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#cacaca"><dl><dd><font color="navy">&lt;</font><font color="navy">adult</font><font color="navy">
              &gt;
            </font><font color="black">Ireland</font><font color="navy">
              &lt;/
              adult
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#9999cc"><dl><dd><font color="navy">&lt;</font><font color="navy">child</font><font color="navy">
              &gt;
            </font><font color="black">Latvia</font><font color="navy">
              &lt;/
              child
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#cacaca"><dl><dd><font color="navy">&lt;</font><font color="navy">adult</font><font color="navy">
              &gt;
            </font><font color="black">Lithuania</font><font color="navy">
              &lt;/
              adult
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#9999cc"><dl><dd><font color="navy">&lt;</font><font color="navy">child</font><font color="navy">
              &gt;
            </font><font color="black">Romania</font><font color="navy">
              &lt;/
              child
              &gt;
            </font></dd></dl></td></tr><tr><td colspan="2" bgcolor="#cacaca"><dl><dd><font color="navy">&lt;</font><font color="navy">adult</font><font color="navy">
              &gt;
            </font><font color="black">Russia</font><font color="navy">
              &lt;/
              adult
              &gt;
            </font></dd></dl></td></tr></tbody></table><br />使用数据：<br />    http://demo.exist-db.org/xmldb/db/examples2.xml<br /><br /><br />2：自定义方法：<br />    使用：http://demo.exist-db.org/sandbox/sandbox.xql<br />    <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> local:minPrice(){<br />  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> $x </span><span style="color: rgb(128, 128, 128);">in</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">to</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">5</span><span style="color: rgb(0, 0, 0);">)<br />  </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">&lt;</span><span style="color: rgb(0, 0, 0);">test</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);">{$x}</span><span style="color: rgb(128, 128, 128);">&lt;/</span><span style="color: rgb(0, 0, 0);">test</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />};<br /><br /></span><span style="color: rgb(128, 128, 128);">&lt;</span><span style="color: rgb(0, 0, 0);">minPrice</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);">{local:minPrice()}</span><span style="color: rgb(128, 128, 128);">&lt;/</span><span style="color: rgb(0, 0, 0);">minPrice</span><span style="color: rgb(128, 128, 128);">&gt;</span></div><div class="item"><div class="xml-element"><span class="xml-element-tag">结果：<br />&lt;</span><span class="xml-element-name">minPrice</span><span class="xml-element-tag">&gt;</span><div class="xml-element"><span class="xml-element-tag">&lt;</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span><span class="xml-text">1</span><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span></div><div class="xml-element"><span class="xml-element-tag">&lt;</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span><span class="xml-text">2</span><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span></div><div class="xml-element"><span class="xml-element-tag">&lt;</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span><span class="xml-text">3</span><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span></div><div class="xml-element"><span class="xml-element-tag">&lt;</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span><span class="xml-text">4</span><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span></div><div class="xml-element"><span class="xml-element-tag">&lt;</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span><span class="xml-text">5</span><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">test</span><span class="xml-element-tag">&gt;</span></div><span class="xml-element-tag">&lt;/</span><span class="xml-element-name">minPrice</span><span class="xml-element-tag">&gt;</span></div></div><br /><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/203834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-29 14:49 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/29/203834.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xml -&gt; xls 简单格式</title><link>http://www.blogjava.net/Good-Game/archive/2007/11/28/163765.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Wed, 28 Nov 2007 10:13:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/11/28/163765.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/163765.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/11/28/163765.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/163765.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/163765.html</trackback:ping><description><![CDATA[
		<br />test.xls 中内容 -&gt;<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Workbook </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="urn:schemas-microsoft-com:office:spreadsheet"</span><span style="color: rgb(255, 0, 0);"><br />xmlns:o</span><span style="color: rgb(0, 0, 255);">="urn:schemas-microsoft-com:office:office"</span><span style="color: rgb(255, 0, 0);"><br />xmlns:x</span><span style="color: rgb(0, 0, 255);">="urn:schemas-microsoft-com:office:excel"</span><span style="color: rgb(255, 0, 0);"><br />xmlns:ss</span><span style="color: rgb(0, 0, 255);">="urn:schemas-microsoft-com:office:spreadsheet"</span><span style="color: rgb(255, 0, 0);"><br />xmlns:html</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/TR/REC-html40"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Worksheet </span><span style="color: rgb(255, 0, 0);">ss:Name</span><span style="color: rgb(0, 0, 255);">="xls1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Table</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Row</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">Data </span><span style="color: rgb(255, 0, 0);">ss:Type</span><span style="color: rgb(0, 0, 255);">="String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">cell a1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Data</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">Data </span><span style="color: rgb(255, 0, 0);">ss:Type</span><span style="color: rgb(0, 0, 255);">="String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">cell b2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Data</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Row</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Row</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">Data </span><span style="color: rgb(255, 0, 0);">ss:Type</span><span style="color: rgb(0, 0, 255);">="String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">cell a2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Data</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">Data </span><span style="color: rgb(255, 0, 0);">ss:Type</span><span style="color: rgb(0, 0, 255);">="String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">cell b3</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Data</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">Cell</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Row</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Table</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Worksheet</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Workbook</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><br />展现的样子-&gt;<br /><table x:str="" style="border-collapse: collapse; width: 108pt;" border="0" cellpadding="0" cellspacing="0" width="144"><col style="width: 54pt;" span="2" width="72" /><tbody><tr style="height: 14.25pt;" height="19"><td style="height: 14.25pt; width: 54pt;" height="19" width="72">cell a1</td><td style="width: 54pt;" width="72">cell b2</td></tr><tr style="height: 14.25pt;" height="19"><td style="height: 14.25pt;" height="19">cell a2</td><td>cell b3</td></tr></tbody></table><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/163765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-11-28 18:13 <a href="http://www.blogjava.net/Good-Game/archive/2007/11/28/163765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>dom4j 学习</title><link>http://www.blogjava.net/Good-Game/archive/2007/11/06/158565.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 06 Nov 2007 07:24:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/11/06/158565.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/158565.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/11/06/158565.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/158565.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/158565.html</trackback:ping><description><![CDATA[直接看代码.. <br />dom4j 的一般使用都在里面了<br />/lib/dom4j-1.6.1.jar<br />/lib/jaxen-1.1-beta-6.jar<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> useDom4j.test.supper;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.File;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.FileOutputStream;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.IOException;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.InputStream;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.OutputStream;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.net.URL;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.Iterator;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.List;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.regex.Matcher;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.regex.Pattern;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.xml.parsers.DocumentBuilder;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.xml.parsers.DocumentBuilderFactory;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.Document;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.DocumentFactory;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.DocumentHelper;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.Element;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.Node;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.QName;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.Visitor;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.VisitorSupport;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.XPath;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.io.DOMReader;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.io.HTMLWriter;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.io.OutputFormat;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.io.SAXReader;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.dom4j.io.XMLWriter;<br /><br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> useDom4jTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">use all</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String path ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> ClassLoader clo;<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> file path -&gt; bin </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String classPath ;<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">use save </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Document doc;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String filese;<br /><br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br />        path </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">useDom4j/test/config/test.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        clo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getClass().getClassLoader();<br />        classPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> System.getProperty(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">java.class.path</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).split(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">]   ;<br />        filese </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> System.getProperty(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">file.separator</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> tearDown() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.tearDown();<br />    }<br /><br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testRead()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        SAXReader sax </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SAXReader();<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">File read</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        Document docF </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  sax.read(<br />                </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(clo.getResource(path).getFile())<br />                    );<br />        assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">is File saxReader err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,docF);<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">InPutStream read </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        Document docI </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sax.read( clo.getResourceAsStream(path) );<br />        assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">is InPutStream saxReader err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,docI);<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">URL read </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        Document docU </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sax.read( clo.getResource(path) );<br />        assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">is Url saxReader err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,docU);<br />        <br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> converts a W3C DOM document into a dom4j document </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testConversion() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />          DocumentBuilderFactory domfac</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">DocumentBuilderFactory.newInstance();<br />          DocumentBuilder dombuilder</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">domfac.newDocumentBuilder();<br />          InputStream input </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  clo.getResourceAsStream(path) ;<br />          org.w3c.dom.Document doc3c </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> dombuilder.parse( input );<br />          DOMReader xmlReader </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DOMReader();<br />          assertEquals( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> Conversion : W3C DOM-&gt; dom4j DOM err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                  xmlReader.read(doc3c) </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> Document,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);"> );<br />      }<br />      <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testCreate()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />          DocumentFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> DocumentFactory.getInstance();<br />          doc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.createDocument();<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">root Create</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">          Element root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> doc.addElement(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">testElement</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />          assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">is root Create err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,root);<br />          <br />           Element author2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.addElement( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">author</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addAttribute( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Toby</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addAttribute( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Germany</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addText( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Tobias Rademacher</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br /><br />            Element author1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.addElement( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">author</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addAttribute( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">James</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addAttribute( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UK</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> )<br />              .addText( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">James Strachan</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br />            <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Test Create <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">use XPath -&gt;jaxen-xxx.jar  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">create Element author2 err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                    doc.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/testElement/author[@name='Toby']</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).getText()<br />                    ,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Tobias Rademacher</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">create Element author1 err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                    doc.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/testElement/author[@location='UK']/@name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).getText()<br />                    ,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">James</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br /><br /><br /><br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testPrintingHTML()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />           String testSaveXml </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">useDom4j/test/config/testHtml.html</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />           <br />           testSaveXml </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> classPath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">filese</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">testSaveXml;<br />          <br />           File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getFile(testSaveXml);<br />           </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Save file.html </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">           HTMLWriter writer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HTMLWriter(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileOutputStream( file ));<br />           writer.write(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SAXReader().read( clo.getResource(path) ));<br />           writer.flush();<br />     }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testIterator(){<br />        Element root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.doc.getRootElement();<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Iterator</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        Iterator elementIterator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.elementIterator();<br />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(elementIterator.hasNext()){<br />          Element element </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element)elementIterator.next();<br />          assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not attr name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">./@name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />          assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not attr location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">./@location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />          assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not Text </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).getText() );<br />        }<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">for -&gt; ./XX</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> ( </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, size </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.nodeCount(); i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> size; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);"> ) {<br />            Node node </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.node(i);<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( node </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> Element ) {<br />              Element element </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element)node;<br />              assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not attr name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">./@name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />                assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not attr location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">./@location</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />                assertNotNull(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">not Text </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).getText() );<br />            }<br />        }<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">List </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        List elements </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.elements();<br />        </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> size </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> elements.size() ;<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( size </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> ) {<br />          elements.subList( </span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);"> ).clear();<br />          assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">List is not clear</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,size</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">elements.size()</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />        }<br /><br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> use test.xml test<br />         xpath -&gt; /project/organization/<br />         &lt;organization&gt;<br />             &lt;name&gt;MetaStuff Ltd.&lt;/name&gt;<br />             &lt;url&gt;</span><span style="color: rgb(0, 128, 0); text-decoration: underline;">http://sourceforge.net/projects/dom4j</span><span style="color: rgb(0, 128, 0);">&lt;/url&gt;<br />             &lt;logo&gt;</span><span style="color: rgb(0, 128, 0); text-decoration: underline;">http://sourceforge.net/sflogo.php?group_id=16035</span><span style="color: rgb(0, 128, 0);">&lt;/logo&gt;<br />          &lt;/organization&gt; <br />          <br />          xpath -&gt; /project/dependencies/dependency[groupId='msv']<br />            &lt;dependency&gt;<br />              &lt;groupId&gt;msv&lt;/groupId&gt;<br />              &lt;artifactId&gt;xsdlib&lt;/artifactId&gt;<br />              &lt;version&gt;20030807&lt;/version&gt;<br />              &lt;url&gt;</span><span style="color: rgb(0, 128, 0); text-decoration: underline;">https://msv.dev.java.net/</span><span style="color: rgb(0, 128, 0);">&lt;/url&gt;<br />            &lt;/dependency&gt;<br />    </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testXpath()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        XPath xpathSelector </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> DocumentHelper.createXPath(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/project/organization/*</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Document docT </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SAXReader().read( clo.getResourceAsStream(path) );<br />        List results </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xpathSelector.selectNodes(docT);<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> ( Iterator iter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> results.iterator(); iter.hasNext(); ) {<br />          Element element </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element) iter.next();<br />          </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(element.getName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)){<br />              assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.getText().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">MetaStuff Ltd.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />          }<br />          </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(element.getName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">url</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)){<br />              assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">url err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.getText().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://sourceforge.net/projects/dom4j</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />          }<br />          </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(element.getName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">logo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)){<br />              assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">logo err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, element.getText().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://sourceforge.net/sflogo.php?group_id=16035</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />          }<br />        }<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> select </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        String url </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> docT.valueOf( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/project/dependencies/dependency[groupId='msv']/url</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br />        assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Url err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, url.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">https://msv.dev.java.net/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />        Number count </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> docT.numberValueOf( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/project/dependencies/dependency[groupId='msv']/version</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br />        assertEquals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Url err</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, count.intValue()</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">20030807</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br />        <br />    }<br /><br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testVisitor(){<br />        Visitor visitor </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> VisitorSupport() {<br />            </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> visit(Element element) {<br />              System.out.println(<br />                </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Entity name: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> element.getName()  </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> text :</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> element.getText()<br />              );<br />            }<br />          };<br /><br />          doc.accept( visitor );<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">  element.clone ;  element.createCopy ;   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testInsertElementAt() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        Element root </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.doc.getRootElement();<br />        Element oldElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element)doc.selectSingleNode(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/testElement/author[@name='Toby']</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Element newElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element) oldElement.clone();<br />        List list </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> root.content();<br />        list.add( root.indexOf(oldElement)</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,newElement );<br /><br />     }<br />    <br />    <br />    <br />    <br />     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testSave()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />           String testSaveXml </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">useDom4j/test/config/testSave.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />           <br />           testSaveXml </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> classPath</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">filese</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">testSaveXml;<br />          <br />           File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getFile(testSaveXml);<br />           </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Save file.xml </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">           XMLWriter writer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XMLWriter(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileOutputStream( file ));<br />           writer.write(doc);<br />           writer.flush();<br />     }<br /><br />     <br />     <br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> File getFile(String testSaveXml) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> IOException {<br />        File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br />           URL url </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> clo.getResource(testSaveXml);<br />           </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(url</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">){<br />               file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(testSaveXml);<br />               file.createNewFile();<br />           }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">{<br />               file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(  url.getFile() );<br />           }<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> file;<br />    }<br />    <br />    <br />}<br /></span></div><br />引用：http://freezingxu.blog.com.cn/archives/2006/1892647.shtml<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />  * 对指定的节点增加属性和文本<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> elmt<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> name<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> value<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> text<br />  * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Element addAttribute(Element elmt,String name,String value){<br />  elmt.addAttribute(name,value);<br />  </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> elmt;<br /> }<br /> <br /> </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />  * 修改指定节点的属性和文本<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> elmt<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> name<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> value<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> text<br />  * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Element setAttribute(Element elmt,String name,String value){<br />  Attribute attribute </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> elmt.attribute(name);<br />  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">attribute.setName(name);</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  attribute.setValue(value);<br />  List list </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList();<br />  list.add(attribute);<br />  elmt.setAttributes(list);<br />  </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> elmt;<br /> }<br /> <br /> </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />  * 删除指定节点的指定属性<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> elmt<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> name<br />  * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Element removeAttribute(Element elmt,String name){<br />  elmt.remove(elmt.attribute(name));<br />  </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> elmt;<br /> }<br /> <br /> </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />  * 输出为文件<br />  * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> doc<br />  * </span><span style="color: rgb(128, 128, 128);">@throws</span><span style="color: rgb(0, 128, 0);"> IOException<br />  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> writeFile(Document doc) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> IOException{<br />  FileWriter out </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileWriter( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">d:/newQuery.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br />  doc.write(out);<br />  out.flush();<br />  out.close();<br /> }</span></div><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/158565.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-11-06 15:24 <a href="http://www.blogjava.net/Good-Game/archive/2007/11/06/158565.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript xpath 自定义方法(级连下拉框)</title><link>http://www.blogjava.net/Good-Game/archive/2007/08/14/136662.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 14 Aug 2007 06:29:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/08/14/136662.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/136662.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/08/14/136662.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/136662.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/136662.html</trackback:ping><description><![CDATA[
		<font color="#ff0000">
				<b>问题:</b>
		</font>IE,FF用 xpath 在javascript动态解读 <br /><font color="#0000ff"><b>解决:</b></font> 自定义jsXpath 类<br /><img src="http://www.blogjava.net/images/blogjava_net/Good-Game/24246/r_select.bmp" /><br />js.js <br /><font color="#008000" size="2"><b>//关键是 jsXpath 类<br />//使用是 new 并 给属性 domx 值 DOMXml <br />//var nodes = obj.<span style="color: rgb(0, 0, 0);">getPathNodes( xpath ); 就是 xpath语句如:</span></b></font><font color="#008000"><span style="color: rgb(0, 0, 0);"><font color="#008000" size="2"><b>//beans/bean<br />//再 var node = obj.next( nodes )<br />//node 可以使用了</b></font><br /></span></font><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> dom </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> jp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> jsXpath();<br /><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> load(ul){<br />    </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Ajax.Request(<br />        ul,<br />        {<br />            method: 'get',<br />            onComplete: action              <br />        });    <br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> action(req){<br /> </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> path </span><span style="color: rgb(0, 0, 0);">=</span><font color="#008000"><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> /beans/bean[string-length(@xid)&lt;3] </span><span style="color: rgb(0, 0, 0);">"</span></font><span style="color: rgb(0, 0, 0);">;<br /> dom </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> req.responseXML ;<br /> jp.domx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> dom ; <br /> </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> list </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  jp.getPathNodes(path) ;<br /> createSelect(jp,list, document.getElementById('ii') );<br /><font color="#008000">//建 select ii  </font><br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> jsXpath(){<br />    </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.nexti </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ;<br />    </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.domx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br />    <br />    </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getPathNodes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(path){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> val </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( navigator.appName.indexOf('Microsoft')</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ){<br />           val  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.evaluate(path,</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.domx ,</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">,XPathResult.ANY_TYPE,</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ) ;<br />        }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">{<br />            </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.domx.setProperty(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SelectionLanguage</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">XPath</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            val </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.domx.documentElement.selectNodes( path ) ;<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> val ;<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.next </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(domp,ii){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( navigator.appName.indexOf('Microsoft')</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ){<br />           </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> domp.iterateNext() ;<br />        }</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">{<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ii</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.nexti </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ii ;<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> domp[</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.nexti</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">];<br />        }<br />    }<br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> createSelect(xpath,doms,sele){<br />        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">{<br />            </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> item</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">xpath.next(doms);<br />            </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(item){<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> opt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">document.createElement('option');<br />                </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> text</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">document.createTextNode( item.firstChild.nodeValue  );<br />                opt.appendChild(text);<br />                opt.setAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,item.getAttribute('xid') );<br />                sele.appendChild(opt);<br />                <br />                item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> xpath.next(doms);<br />            }<br />        }</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(e){dump(e);}<br />}<br /><br /><font color="#006400">//建 select jj 与 select ii的 selectedIndex 有关</font><br /></span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> duSel(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> sele </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById('jj');<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> sdom </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById('ii');<br />        <br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> num </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sele.getElementsByTagName('option').length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">; <br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">num; i</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ; i</span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">) <br />            sele.remove(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">); <br />        <br />         </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> skey </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sdom.options[ sdom.selectedIndex ].value<br /><br />         </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> path </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/beans/bean[  starts-with( @xid , '</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">skey</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">') and string-length(@xid)&gt;3  ]</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><br />         </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> jpp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> jsXpath();<br />         jpp.domx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> dom ; <br />         </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> lj </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> jpp.getPathNodes(path);<br /><br />         createSelect(jpp,lj, document.getElementById('jj') );<br />}<br /></span></div><br />xml.xml <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="GB2312" standalone="no"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">xid</span><span style="color: rgb(0, 0, 255);">='01' </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">北京局</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">xid</span><span style="color: rgb(0, 0, 255);">='0101'&gt;ftd&lt;/bean&gt;<br />    </span><span style="color: rgb(255, 0, 0);">&lt;bean xid</span><span style="color: rgb(0, 0, 255);">='0102'&gt;tsd&lt;/bean&gt;<br /><br />    </span><span style="color: rgb(255, 0, 0);">&lt;bean xid</span><span style="color: rgb(0, 0, 255);">='02'&gt;沈阳局&lt;/bean&gt;<br />    </span><span style="color: rgb(255, 0, 0);">&lt;bean xid</span><span style="color: rgb(0, 0, 255);">='0202'&gt;sy1&lt;/bean&gt;<br />    </span><span style="color: rgb(255, 0, 0);">&lt;bean xid</span><span style="color: rgb(0, 0, 255);">='0203'&gt;sy2&lt;/bean&gt;<br />    </span><span style="color: rgb(255, 0, 0);">&lt;bean xid</span><span style="color: rgb(0, 0, 255);">='0204'&gt;sy3&lt;/bean&gt;<br /></span><span style="color: rgb(255, 0, 0);">&lt;/beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br />xpath.html <font color="#006400">//级连的 下拉框出来了</font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta </span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);"> content</span><span style="color: rgb(0, 0, 255);">="text/html; charset=gb2312"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script </span><span style="color: rgb(255, 0, 0);">language</span><span style="color: rgb(0, 0, 255);">='JavaScript' </span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">="js/js.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script </span><span style="color: rgb(255, 0, 0);">language</span><span style="color: rgb(0, 0, 255);">="JavaScript"</span><span style="color: rgb(255, 0, 0);"> src</span><span style="color: rgb(0, 0, 255);">="lib/prototype/prototype.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script </span><span style="color: rgb(255, 0, 0);">language</span><span style="color: rgb(0, 0, 255);">='JavaScript' </span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">='js/xpath.js'</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body </span><span style="color: rgb(255, 0, 0);">onload</span><span style="color: rgb(0, 0, 255);">='load( </span><span style="color: rgb(255, 0, 0);">"./xml/xml.xml" )'</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">    <br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">select </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="ii"</span><span style="color: rgb(255, 0, 0);"> onchange</span><span style="color: rgb(0, 0, 255);">='duSel();'</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">option </span><span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">=""</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">--段选择--</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">option</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">select</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">select </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="jj"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">option </span><span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">=""</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">--车间选择--</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">option</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">select</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><font color="#9acd32"><b>心得: xpath 是好东西 好东西啊 </b></font><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/136662.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-08-14 14:29 <a href="http://www.blogjava.net/Good-Game/archive/2007/08/14/136662.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript  Xpath 小例</title><link>http://www.blogjava.net/Good-Game/archive/2007/08/13/136365.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Mon, 13 Aug 2007 05:58:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/08/13/136365.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/136365.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/08/13/136365.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/136365.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/136365.html</trackback:ping><description><![CDATA[
		<font color="#ff0000">
				<b>问题：</b>
		</font> java 可以用 xpath ; javascriopt 也可以！<br /><font color="#0000ff"><b>解决：</b></font> document.evaluate 方法 <br /><b><font color="#ffa500">参考：</font></b><a href="http://blog.csdn.net/ismycxp/archive/2007/05/12/1605650.aspx">浏览器中的XPath支持</a><br />xpath.html<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta </span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);"> content</span><span style="color: rgb(0, 0, 255);">="text/html; charset=gb2312"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script </span><span style="color: rgb(255, 0, 0);">language</span><span style="color: rgb(0, 0, 255);">='JavaScript' </span><span style="color: rgb(255, 0, 0);">src</span><span style="color: rgb(0, 0, 255);">="js/js.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script </span><span style="color: rgb(255, 0, 0);">language</span><span style="color: rgb(0, 0, 255);">="JavaScript"</span><span style="color: rgb(255, 0, 0);"> src</span><span style="color: rgb(0, 0, 255);">="lib/prototype/prototype.js"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 255);"></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body </span><span style="color: rgb(255, 0, 0);">onload</span><span style="color: rgb(0, 0, 255);">='load( </span><span style="color: rgb(255, 0, 0);">"./xml/xml.xml" )'</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;<br /><font color="#006400">// xpath.js 是一个扩展包在这里是可以统一 方法<font color="#008000"></font></font><font color="#008000">IE ，FF都可以使用 evaluate方法 <br />// <b>http://www.blogjava.net/Files/Good-Game/xpath.rar</b> 下载<br />// 说明  <b>http://dev.infoaccelerator.net/spryDocs/overview-summary.html</b><br /></font></span><span style="color: rgb(0, 0, 0);"></span></div><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/136365.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-08-13 13:58 <a href="http://www.blogjava.net/Good-Game/archive/2007/08/13/136365.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java Xpath 小例</title><link>http://www.blogjava.net/Good-Game/archive/2007/08/03/134261.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 03 Aug 2007 07:46:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/08/03/134261.html</guid><description><![CDATA[参考：<font color="#006400">http://www.cnblogs.com/zixin/category/60411.html<br /></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.xpath.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.input.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.output.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.xpath.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.saxpath.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">; <br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> TestXML { <br />  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) { <br />    </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {        <br />        SAXBuilder sb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SAXBuilder();        <br />        Document doc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sb.build(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileInputStream(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/book.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));        <br />        String strPath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">//book/author</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;       <br />        XPath path </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> XPath.newInstance(strPath);        <br />        List lst </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> path.selectNodes(doc);        <br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Iterator it </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> lst.iterator(); it.hasNext();) {            <br />            Element at </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Element) it.next();            <br />            System.out.println(at.getText());        <br />        }<br /><br />       } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception e) {        <br />       e.printStackTrace();<br />   }<br />  }<br />} <br /></span></div><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/134261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-08-03 15:46 <a href="http://www.blogjava.net/Good-Game/archive/2007/08/03/134261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>