﻿<?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-向左走，向右走。。。-随笔分类-JavaScript相关技术</title><link>http://www.blogjava.net/tower/category/985.html</link><description>永远不回头</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 00:19:09 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 00:19:09 GMT</pubDate><ttl>60</ttl><item><title>使用JavaScript来实现页面间的参数传递</title><link>http://www.blogjava.net/Tower/archive/2005/04/18/3417.html</link><dc:creator>非飞</dc:creator><author>非飞</author><pubDate>Mon, 18 Apr 2005 07:52:00 GMT</pubDate><guid>http://www.blogjava.net/Tower/archive/2005/04/18/3417.html</guid><wfw:comment>http://www.blogjava.net/Tower/comments/3417.html</wfw:comment><comments>http://www.blogjava.net/Tower/archive/2005/04/18/3417.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/Tower/comments/commentRss/3417.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Tower/services/trackbacks/3417.html</trackback:ping><description><![CDATA[<BR>在JavaScript中，可以通过window.location来获取url地址。但是window.location是一个对象，没有办法直接从里面获取出我们需要的参数。通常的做法就是使用一个隐藏的&lt;input&gt;,通过将window.location负值给input。其目的就是为了将location转换成String。写的过程中总是觉得太复杂了，后来发现使用document.URL就可以解决这个问题。<img src ="http://www.blogjava.net/Tower/aggbug/3417.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Tower/" target="_blank">非飞</a> 2005-04-18 15:52 <a href="http://www.blogjava.net/Tower/archive/2005/04/18/3417.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaScript读取服务器端的xml</title><link>http://www.blogjava.net/Tower/archive/2005/04/09/3026.html</link><dc:creator>非飞</dc:creator><author>非飞</author><pubDate>Sat, 09 Apr 2005 04:23:00 GMT</pubDate><guid>http://www.blogjava.net/Tower/archive/2005/04/09/3026.html</guid><wfw:comment>http://www.blogjava.net/Tower/comments/3026.html</wfw:comment><comments>http://www.blogjava.net/Tower/archive/2005/04/09/3026.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Tower/comments/commentRss/3026.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Tower/services/trackbacks/3026.html</trackback:ping><description><![CDATA[<P>今天在帮朋友写一个简单的产品发布网站，由于使用的空间是静态的，没有办法只能在javascript上下功夫了。首先想到的便是RIA,上网google了一下，发现这样的东西还真不少，可谓是十八般武艺各显灵通。看了看文明的bindows，感觉真的非常的好。可是选择它对于我要做的东西，可以说是过于复杂了。（<A href="http://www.bindows.net">http://www.bindows.net</A> 有兴趣的朋友可以去看看）。<BR>搜索了半天最后还是决定，采用javascript读取服务器端xml文件的办法来实现。尝试了一下感觉还不错，确定就是对使用的浏览器有依赖。<BR>先写了一个商品的xml文件：<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml&nbsp;version="1.0"</SPAN><SPAN style="COLOR: #0000ff">?&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">root</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">product&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="0001"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="product1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;price</SPAN><SPAN style="COLOR: #0000ff">="10.00"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">description</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Detail&nbsp;Description<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">description</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">product</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">product&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="0002"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="product2"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;price</SPAN><SPAN style="COLOR: #0000ff">="20.00"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">description</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Detail&nbsp;Description<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">description</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">product</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">root</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV></DIV>
<P>&nbsp;</P>
<P>使用javascript来读入xml实在是相当的简单，只需要两句话就可以搞定：<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;装载xml文件的函数</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;loadXML(fileName)&nbsp;{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;定义一个xml&nbsp;dom对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;xmlDoc&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ActiveXObject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Microsoft.XMLDOM</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;xmlDoc.load(fileName);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;xmlObj&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;xmlDoc.documentElement;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}</SPAN></DIV></DIV>
<P>&nbsp;</P>
<P>指定要载入的xml文件名就可以完成对xml的读入。<BR></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;载入xml文件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">loadXML(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">product.xml</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);</SPAN></DIV></DIV>
<P>&nbsp;</P>
<P>得到xml对象后就可以适用对象提供的相应方法和属性来获取xml中定义的数据信息。<BR>xmlObj.hasChildNodes来判断是否含有子项；<BR>xmlObj.childNodes.lenght 得到包含的子项的数量<BR>子项可以用数字来作为索引，以product.xml为例。如果我们要获取第二条商品时，可以用xmlObj.childNodes(1)来获得，xmlObj.childNodes(1).childNodes(0)得到的是description<BR>xmlObj.childNodes(1).childNodes(0).text 得到description的值<BR>xmlObj.childNodes(1).getAttribute("name") 得到第二条商品的名字<BR><BR><BR></P><img src ="http://www.blogjava.net/Tower/aggbug/3026.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Tower/" target="_blank">非飞</a> 2005-04-09 12:23 <a href="http://www.blogjava.net/Tower/archive/2005/04/09/3026.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>