<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[DOMDocument 属性和方法 ]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[Web 技术 ]]></category>
<pubDate>Sat, 29 Sep 2007 17:01:47 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	 &nbsp;最近发现DOMDocument对象很重要,还有XMLHTTP也很重要<br/><br/>注意大小写一定不能弄错.<br/><br/>属性:<br/><br/> <br/><br/> 1Attributes &nbsp; &nbsp; 存储节点的属性列表(只读)<br/> 2childNodes &nbsp; &nbsp; 存储节点的子节点列表(只读)<br/> 3dataType &nbsp; &nbsp; 返回此节点的数据类型<br/> 4Definition &nbsp; &nbsp; 以DTD或XML模式给出的节点的定义(只读)<br/> 5Doctype &nbsp; &nbsp; 指定文档类型节点(只读)<br/> 6documentElement &nbsp; &nbsp; 返回文档的根元素(可读写)<br/> 7firstChild &nbsp; &nbsp; 返回当前节点的第一个子节点(只读)<br/> 8Implementation &nbsp; &nbsp; 返回XMLDOMImplementation对象<br/> 9lastChild &nbsp; &nbsp; 返回当前节点最后一个子节点(只读)<br/>10nextSibling &nbsp; &nbsp; 返回当前节点的下一个兄弟节点(只读)<br/>11nodeName &nbsp; &nbsp; 返回节点的名字(只读)<br/>12nodeType &nbsp; &nbsp; 返回节点的类型(只读)<br/>13nodeTypedValue &nbsp; &nbsp; 存储节点值(可读写)<br/>14nodeValue &nbsp; &nbsp; 返回节点的文本(可读写)<br/>15ownerDocument &nbsp; &nbsp; 返回包含此节点的根文档(只读)<br/>16parentNode &nbsp; &nbsp; 返回父节点(只读)<br/>17Parsed &nbsp; &nbsp; 返回此节点及其子节点是否已经被解析(只读)<br/>18Prefix &nbsp; &nbsp; 返回名称空间前缀(只读)<br/>19preserveWhiteSpace &nbsp; &nbsp; 指定是否保留空白(可读写)<br/>20previousSibling &nbsp; &nbsp; 返回此节点的前一个兄弟节点(只读)<br/>21Text &nbsp; &nbsp; 返回此节点及其后代的文本内容(可读写)<br/>22url &nbsp; &nbsp; 返回最近载入的XML文档的URL(只读)<br/>23Xml &nbsp; &nbsp; 返回节点及其后代的XML表示(只读)<br/><br/>方法:<br/><br/> 1appendChild &nbsp; &nbsp; 为当前节点添加一个新的子节点,放在最后的子节点后<br/> 2cloneNode &nbsp; &nbsp; 返回当前节点的拷贝<br/> 3createAttribute &nbsp; &nbsp; 创建新的属性<br/> 4createCDATASection &nbsp; &nbsp; 创建包括给定数据的CDATA段<br/> 5createComment &nbsp; &nbsp; 创建一个注释节点<br/> 6createDocumentFragment &nbsp; &nbsp; 创建DocumentFragment对象<br/> 7createElement &nbsp; &nbsp; 创建一个元素节点<br/> 8createEntityReference &nbsp; &nbsp; 创建EntityReference对象<br/> 9createNode &nbsp; &nbsp; 创建给定类型,名字和命名空间的节点<br/>10createPorcessingInstruction &nbsp; &nbsp; 创建操作指令节点<br/>11createTextNode &nbsp; &nbsp; 创建包括给定数据的文本节点<br/>12getElementsByTagName &nbsp; &nbsp; 返回指定名字的元素集合<br/>13hasChildNodes &nbsp; &nbsp; 返回当前节点是否有子节点<br/>14insertBefore &nbsp; &nbsp; 在指定节点前插入子节点<br/>15Load &nbsp; &nbsp; 导入指定位置的XML文档<br/>16loadXML &nbsp; &nbsp; 导入指定字符串的XML文档<br/>17removeChild &nbsp; &nbsp; 从子结点列表中删除指定的子节点<br/>18replaceChild &nbsp; &nbsp; 从子节点列表中替换指定的子节点<br/>19Save &nbsp; &nbsp; 把XML文件存到指定节点<br/>20selectNodes &nbsp; &nbsp; 对节点进行指定的匹配,并返回匹配节点列表<br/>21selectSingleNode &nbsp; &nbsp; 对节点进行指定的匹配,并返回第一个匹配节点<br/>22transformNode &nbsp; &nbsp; 使用指定的样式表对节点及其后代进行转换<br/>23transformNodeToObject &nbsp; &nbsp; 使用指定的样式表将节点及其后代转换为对象<br/><br/><br/>*************************************************************************************************************************<br/><br/><br/>DOM(文档对象模型)<br/>DOM(文档对象模型)概念的推出,这个API使HTML如虎添翼,但是有些学DHTML的朋友还是有些困挠,只是因为目前的手册的书写不太科学,是按字母<br/><br/>来分的,不便查阅.其实DOM中最关键是要掌握节点与节点之间的关系(between node andnode),想学习DHTML中的DOM千万不要从头到尾地看遍所<br/><br/>有的属性和方法,你有三国时张松的"过目不忘"的本领吗?没有吧,那就听我分析一下：<br/><br/>其实DOM教给我们的就是一个层次结构，你可以理解为一个树形结构，就像我们的目录一样，一个根目录，根目录下有子目录，子目录下还有子<br/><br/>目录……<br/><br/>根节点：<br/><br/><br/>DOM把层次中的每一个对象都称之为节点（NODE），以HTML超文本标记语言为例：整个文档的一个根就是< html >,在DOM中可以使用<br/><br/>document.documentElement来访问它，它就是整个节点树的根节点（ROOT）<br/><br/>子节点：<br/><br/>一般意义上的节点，根节点以下最大子节点就是主文档区< &nbsp;body >了，要访问到body标签，在脚本中应该写：<br/>document.body<br/>body区以内所有的文本及HTML标签都是文档的节点，分别称为文本节点、元素节点（或者叫标签节点），大家知道HTML说到底只是文本而矣，<br/><br/>不论怎么样的网页必然由这两个节点组成，也只能由这两个节点组成<br/><br/>节点之间的关系：<br/><br/>节点之间的关系也是DOM中最重要的一个关节，如何正确地引用到节点对象，一定要清楚节点树各个节点的相互描述方式，在DHTML里，<br/><br/>Javascript脚本就用了各个节点对象的一整套方法和属性去描述另外的节点对象。<br/><br/><br/>节点的绝对引用：<br/>返回文档的根节点<br/>document.documentElement<br/>返回当前文档中被击活的标签节点<br/>document.activeElement<br/>返回鼠标移出的源节点<br/>event.fromElement<br/>返回鼠标移入的源节点<br/>event.toElement<br/>返回激活事件的源节点<br/>event.srcElement<br/><br/>节点的相对引用：(设当前对节点为node)<br/>返回父节点<br/>node.parentNode<br/>node.parentElement<br/>返回子节点集合（包含文本节点及标签节点）<br/>node.childNodes<br/>返回子标签节点集合<br/>node.children<br/>返回子文本节点集合<br/>node.textNodes<br/>返回第一个子节点<br/>node.firstChild<br/>返回最后一个子节点<br/>node.lastChild<br/>返回同属下一个节点<br/>node.nextSibling<br/>返回同属上一个节点<br/>node.previousSibling<br/><br/>节点的各种操作：(设当前的节点为node)<br/><br/>新增标签节点句柄：<br/>document.createElement(sNode) //参数为要新添的节点标签名，例：newnode=document.createElement("div");<br/><br/>1、添加节点：<br/>追加子节点：<br/>node.appendChild(oNode) //oNode为生新增的节点句柄,例：node.appendChild(newnode)<br/>应用标签节点<br/>node.applyElment(oNode,sWhere)//oNode为生新增的节点句柄,sWhere有两个值：outside / inside，加在当前节点外面还是里面<br/>插入节点<br/>inode.insertBefore()<br/>node.insertAdjacentElement()<br/>node.replaceAdjacentText()<br/><br/>2、修改节点：<br/><br/>删除节点<br/>node.remove()<br/>node.removeChild()<br/>node.removeNode()<br/><br/>替换节点<br/>node.replaceChild()<br/>node.replaceNode()<br/>node.swapNode()<br/><br/><br/>2、复制节点：<br/>返回复制复制节点引用<br/>node.cloneNode(bAll)//bAll为布尔值，true / false 是否克隆该节点所有子节点<br/><br/>3、节点信息<br/>是否包含某节点<br/>node.contains()<br/>是否有子节点<br/>node.hasChildNodes()<br/><br/>************************************************************************************************************************<br/><br/>下面为javascript操作xml<br/><br/><div class="code">&lt;script language=&quot;JavaScript&quot;&gt;<br/>&lt;!--<br/>var doc = new ActiveXObject(&quot;Msxml2.DOMDocument&quot;); //ie5.5+,CreateObject(&quot;Microsoft.XMLDOM&quot;) <br/><br/><br/>//加载文档<br/>//doc.load(&quot;b.xml&quot;);<br/><br/>//创建文件头<br/>var p = doc.createProcessingInstruction(&quot;xml&quot;,&quot;version=&#039;1.0&#039; &nbsp;encoding=&#039;gb2312&#039;&quot;);<br/><br/> &nbsp; &nbsp;//添加文件头<br/> &nbsp; &nbsp;doc.appendChild(p);<br/><br/>//用于直接加载时获得根接点<br/>//var root = doc.documentElement;<br/><br/>//两种方式创建根接点<br/>// &nbsp; &nbsp;var root = doc.createElement(&quot;students&quot;);<br/> &nbsp; &nbsp;var root = doc.createNode(1,&quot;students&quot;,&quot;&quot;);<br/><br/> &nbsp; &nbsp;//创建子接点<br/> &nbsp; &nbsp;var n = doc.createNode(1,&quot;ttyp&quot;,&quot;&quot;);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//指定子接点文本<br/> &nbsp; &nbsp; &nbsp; &nbsp;//n.text = &quot; this is a test&quot;;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;//创建孙接点<br/> &nbsp; &nbsp;var o = doc.createElement(&quot;sex&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;o.text = &quot;男&quot;; &nbsp; &nbsp;//指定其文本<br/><br/> &nbsp; &nbsp;//创建属性<br/> &nbsp; &nbsp;var r = doc.createAttribute(&quot;id&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;r.value=&quot;test&quot;;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加属性<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.setAttributeNode(r);<br/><br/> &nbsp; &nbsp;//创建第二个属性 &nbsp; &nbsp;<br/> &nbsp; &nbsp;var r1 = doc.createAttribute(&quot;class&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;r1.value=&quot;tt&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加属性<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.setAttributeNode(r1);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//删除第二个属性<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.removeAttribute(&quot;class&quot;);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加孙接点<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.appendChild(o);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加文本接点<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.appendChild(doc.createTextNode(&quot;this is a text node.&quot;));<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加注释<br/> &nbsp; &nbsp; &nbsp; &nbsp;n.appendChild(doc.createComment(&quot;this is a comment&amp;amp;#92;n&quot;));<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加子接点<br/> &nbsp; &nbsp; &nbsp; &nbsp;root.appendChild(n);<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;//复制接点<br/> &nbsp; &nbsp;var m = n.cloneNode(true);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;root.appendChild(m);<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;//删除接点<br/> &nbsp; &nbsp; &nbsp; &nbsp;root.removeChild(root.childNodes(0));<br/><br/> &nbsp; &nbsp;//创建数据段<br/> &nbsp; &nbsp;var c = doc.createCDATASection(&quot;this is a cdata&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;c.text = &quot;hi,cdata&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp;//添加数据段<br/> &nbsp; &nbsp; &nbsp; &nbsp;root.appendChild(c);<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;//添加根接点<br/> &nbsp; &nbsp;doc.appendChild(root);<br/><br/> &nbsp; &nbsp;//查找接点<br/> &nbsp; &nbsp;var a = doc.getElementsByTagName(&quot;ttyp&quot;);<br/> &nbsp; &nbsp;//var a = doc.selectNodes(&quot;//ttyp&quot;);<br/><br/> &nbsp; &nbsp;//显示改接点的属性<br/> &nbsp; &nbsp;for(var i= 0;i&lt;a.length;i++)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(a&#91;i&#93;.xml);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(var j=0;j&lt;a&#91;i&#93;.attributes.length;j++)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(a&#91;i&#93;.attributes&#91;j&#93;.name);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;//修改节点,利用XPATH定位节点<br/> &nbsp; &nbsp;var b = doc.selectSingleNode(&quot;//ttyp/sex&quot;);<br/> &nbsp; &nbsp;b.text = &quot;女&quot;;<br/><br/> &nbsp; &nbsp;//alert(doc.xml);<br/><br/> &nbsp; &nbsp;//XML保存（需要在服务端，客户端用FSO）<br/> &nbsp; &nbsp;//doc.save();<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;//查看根接点XML<br/> &nbsp; &nbsp;if(n)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(n.ownerDocument.xml);<br/> &nbsp; &nbsp; &nbsp;&#125;<br/><br/>//--&gt;<br/>&lt;/script&gt; </div><br/>
]]>
</description>
</item><item>
<link>https://atim.cn/post//#blogcomment</link>
<title><![CDATA[[评论] DOMDocument 属性和方法 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>