<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 14, 文章 - 39, 評論 - 17, 引用 - 0
    數(shù)據(jù)加載中……

    資料:Javascript 操作XML[轉(zhuǎn)]

    ?

    一般從服務(wù)端的返回可以得到一個XML對象。
    例如服務(wù)器返回的:XMLHttpRequest.ResponseXML
    這里的XMLHttpRequest就是ajax的核心對象。
    在IE下可以這樣創(chuàng)建:xmlHttp?
    = ? new ?ActiveXObject( " Microsoft.XMLHTTP " ).
    javascript操作XML先創(chuàng)建一個XML?DOM對象:var?dom?
    = ? new ?ActiveXObject( " Microsoft.XMLDOM " );
    然后dom.loadXML(ResponseXML)就ok了。
    接下來就可以操作xml,獲取內(nèi)容了。
    一些常用的函數(shù)如下(一些在網(wǎng)上收集的,一些時平時老大教的):
    Microsoft.XMLDOM?對象常用的屬性:
    1 、attributes?屬性,返回當(dāng)前節(jié)點的屬性列表
    2 、childNodes?屬性,返回當(dāng)前節(jié)點的所有子節(jié)點列表
    3 、documentElement?屬性,返回xml文件的根節(jié)點,通過Microsoft.XMLDOM對象名來調(diào)用
    4 、firstChild?屬性、lastChild?屬性,返回當(dāng)前節(jié)點的第一個子(最后一個)元素(如果沒有子節(jié)點是不是返回
    第一個屬性?)
    5 、nextSibling?(previousSibling?)屬性,下一個兄弟節(jié)點。
    6 、nodeName?屬性,返回節(jié)點的標簽名字
    7 、nodeValue?屬性,傳回指定節(jié)點相關(guān)的文字(不是屬性,就是 * 號的這個內(nèi)容? **
    8 、ownerDocument?屬性,根節(jié)點
    9 、parentNode?屬性,傳回目前節(jié)點的父節(jié)點。只能應(yīng)用在有父節(jié)點的節(jié)點中。
    搞一個例子:
    function?Add()
    {
    var?dom?
    = ? new ?ActiveXObject( " Microsoft.XMLDOM " );?
    dom.loadXML(ret);?
    if ?(dom.documentElement? != ? null )
    {?
    var?nodes?
    = ?dom.documentElement.selectNodes( " //SelectItem " );? // 得到根節(jié)點下所有SelectItem節(jié)點
    if ?(nodes? != ? null )?
    {
    for (var?i = 0 ;i?
    一些常用的函數(shù):
    1 、AppendChild?方法,加上一個節(jié)點當(dāng)作指定節(jié)點最后的子節(jié)點。
    2 、cloneNode(deep)方法,deep?是一個布爾值。如果為true,此節(jié)點會復(fù)制以指定節(jié)點發(fā)展出去的所有節(jié)
    點。如果是false,只有指定的節(jié)點和它的屬性被復(fù)制。
    3 、createAttribute(name)方法,建立一個指定名稱的屬性。
    4 、createElement?方法,建立一個指定名稱的元素。
    5 、xmlDocument.createNode(type,?name,?nameSpaceURI);type?用來確認要被建立的節(jié)點型態(tài),name?是一個字符
    串來確認新節(jié)點的名稱,命名空間的前綴則是選擇性的。nameSpaceURI?是一個定義命名空間URI?的字
    符串。如果前綴被包含在名稱參數(shù)中,此節(jié)點會在nameSpaceURI?的內(nèi)文中以指定的前綴建立。如果不
    包含前綴,指定的命名空間會被視為預(yù)設(shè)的命名空間。
    6 、getElementsByTagName?方法,傳回指定名稱的元素集合。
    7 、haschildnodes?方法,要解釋嗎?
    8 、insertBefore?方法,在指定的節(jié)點前插入一個子節(jié)點。xmlDocumentNode.insertBefore
    (newChild,refChild);refChild?是參照節(jié)點的地址。新子節(jié)點被插到參照節(jié)點之前。如果refChild?參數(shù)沒有包含
    在內(nèi),新的子節(jié)點會被插到子節(jié)點列表的末端。
    9 、load?方法和loadXML?方法,前這從url,后者從字符串片斷。
    10 、nodeFromID?方法,傳回節(jié)點ID?符合指定值的節(jié)點。
    11 、removeChild?方法和replaceChild(newChild,oldChild),顧名思義
    12 、selectNodes和selectSingleNode?方法,傳回所有符合提供樣式的節(jié)點。參數(shù)為一包含XSL?樣式的字符串。
    以下收集了一些MSDN的例子
    (
    1 )
    var?xmlDoc?
    = ? new ?ActiveXObject( " Msxml2.DOMDocument.3.0 " );
    var?rootElement
    = xmlDoc.createElement( " memo " );
    xmlDoc.appendChild(rootElement);(
    2 )?var?xmlDoc? = ? new ?ActiveXObject( " Msxml2.DOMDocument.3.0 " );
    var?rootElement
    = xmlDoc.createElement( " memo " );
    rootElement.setAttribute(
    " author " ,? " Pat?Coleman " );? // 屬性author的值為Pat?Coleman
    xmlDoc.appendChild(rootElement);
    (
    3 )?var?xmlDoc? = ? new ?ActiveXObject( " Msxml2.DOMDocument.3.0 " );
    var?rootElement
    = xmlDoc.createElement( " memo " );
    var?memoAttribute
    = xmlDoc.createAttribute( " author " );
    var?memoAttributeText
    = xmlDoc.createTextNode( " Pat?Coleman " );
    memoAttribute.appendChild(memoAttributeText);
    rootElement.setAttributeNode(memoAttribute);
    xmlDoc.appendChild(rootElement);
    // 這個例子和(2)同樣效果,但是用不同的方法,這里把attribute也當(dāng)做一個節(jié)點,attribute?node的
    子節(jié)點只可以是textnode,所以這里要先創(chuàng)建一個textnode在賦給他。
    4
    var?xmlDoc?
    = ? new ?ActiveXObject( " Msxml2.DOMDocument.3.0 " );
    var?rootElement
    = xmlDoc.createElement( " memo " );? // 創(chuàng)建一個元素
    var?memoAttribute = xmlDoc.createAttribute( " author " );? // 創(chuàng)建一個屬性
    var?memoAttributeText = xmlDoc.createTextNode( " Pat?Coleman " );? // 創(chuàng)建一個文本節(jié)點
    var?toElement = xmlDoc.createElement( " to " );? // 再創(chuàng)建一個元素
    var?toElementText = xmlDoc.createTextNode( " Carole?Poland " );? // 再創(chuàng)建一個文本節(jié)點
    memoAttribute.appendChild(memoAttributeText);
    xmlDoc.appendChild(rootElement);
    rootElement.setAttributeNode(memoAttribute);
    rootElement.appendChild(toElement);
    toElement.appendChild(toElementText);


    屬性:
    attributes
    Contains?the?list?of?attributes?
    for ? this ?node.?Read - only.
    baseName
    * Returns?the?base?name? for ?the?name?qualified?with?the?namespace.?Read - only.
    childNodes
    Contains?a?node?list?containing?the?children?nodes.?Read
    - only.
    dataType
    * Specifies?the?data?type? for ? this ?node.?Read / write.
    definition
    * Returns?the?definition?of?the?node?in?the?document?type?definition?(DTD)?or?schema.?Read - only.
    firstChild
    Contains?the?first?child?of?the?node.?Read
    - only.
    lastChild
    Returns?the?last?child?node.?Read
    - only.
    name
    Contains?the?attribute?name.?Read
    - only.
    namespaceURI
    * Returns?the?Uniform?Resource?Identifier?(URI)? for ?the?namespace.?Read - only.
    nextSibling
    Contains?the?next?sibling?of?
    this ?node?in?the?parent ' s?child?list.?Read-only.
    nodeName
    Contains?the?qualified?name?of?the?element,?attribute,?or?entity?reference,?or?a?fixed?string?
    for ?other?node?types.?Read - only.
    nodeType
    Specifies?the?XML?Document?Object?Model?(DOM)?node?type,?which?determines?valid?values?and?whether?the?node?can?have?child?nodes.?Read
    - only.
    nodeTypedValue
    * Contains?the?node?value?expressed?in?its?defined?data?type.?Read / write.
    nodeTypeString
    * Returns?the?node?type?in?string?form.?Read - only.
    nodeValue
    Contains?the?text?associated?with?the?node.?Read
    / write.
    ownerDocument
    Returns?the?root?of?the?document?that?contains?the?node.?Read
    - only.
    parentNode
    Contains?the?parent?node.?Read
    - only.
    parsed
    * Indicates?the?parsed?status?of?the?node?and?child?nodes.?Read - only.
    prefix
    * Returns?the?namespace?prefix.?Read - only.
    previousSibling
    Contains?the?previous?sibling?of?
    this ?node?in?the?parent ' s?child?list.?Read-only.
    specified
    Indicates?whether?the?node?(usually?an?attribute)?is?explicitly?specified?or?derived?from?a?
    default ?value?in?the?document?type?definition?(DTD)?or?schema.?Read - only.
    text
    Represents?the?text?content?of?the?node?or?the?concatenated?text?representing?the?node?and?its?descendants.?Read
    / write.
    value
    Contains?the?attribute?value.?Read
    / write.
    xml
    Contains?the?XML?representation?of?the?node?and?all?its?descendants.?Read
    - only.
    方法:
    appendChild
    Appends?
    new ?child?node?as?the?last?child?of? this ?node.
    cloneNode
    Clones?a?
    new ?node.
    hasChildNodes
    Provides?a?fast?way?to?determine?whether?a?node?has?children.
    insertBefore
    Inserts?a?child?node?to?the?left?of?the?specified?node?or?at?the?end?of?the?list.
    removeChild
    Removes?the?specified?child?node?from?the?list?of?children?and?returns?it.
    replaceChild
    Replaces?the?specified?old?child?node?with?the?supplied?
    new ?child?node.
    selectNodes
    Applies?the?specified?pattern
    - matching?operation?to? this ?node ' s?context?and?returns?the?list?of?matching?nodes?as?IXMLDOMNodeList.
    selectSingleNode
    Applies?the?specified?pattern
    - matching?operation?to? this ?node ' s?context?and?returns?the?first?matching?node.
    transformNode
    Processes?
    this ?node?and?its?children?using?the?supplied?XSL?Transformations?(XSLT)?style?sheet?and?returns?the?resulting?transformation.
    transformNodeToObject
    Processes?
    this ?node?and?its?children?using?the?supplied?XSL?Transformations?(XSLT)?style?sheet?and?returns?the?resulting?transformation?in?the?supplied?object.?


    posted on 2006-11-22 18:19 mlw2000 閱讀(382) 評論(0)  編輯  收藏 所屬分類: JavaScript

    主站蜘蛛池模板: 亚洲娇小性xxxx色| 亚洲国产成人精品不卡青青草原| 亚洲人成网男女大片在线播放 | 亚洲熟妇无码久久精品| 69视频在线观看高清免费| 亚洲精品国产成人99久久| 18禁美女黄网站色大片免费观看| 亚洲国产香蕉碰碰人人| 999国内精品永久免费视频| 亚洲午夜电影一区二区三区| 四虎免费在线观看| 婷婷亚洲综合五月天小说在线| 亚洲国产精品成人一区| 香蕉免费看一区二区三区| 亚洲国产精品VA在线看黑人| 精品国产免费一区二区三区香蕉| 亚洲综合一区二区精品导航| 噼里啪啦免费观看高清动漫4| 亚洲国产精品99久久久久久| 免费播放特黄特色毛片| 国产成人免费ā片在线观看老同学| 亚洲AV无码一区东京热久久| 成年免费大片黄在线观看岛国| 亚洲乱码无人区卡1卡2卡3| 亚洲国产精品一区二区第一页免| 色www永久免费| 亚洲人成电影院在线观看| 国产国产人免费人成免费视频| 成人免费一区二区三区| 亚洲伊人久久精品| 又粗又大又长又爽免费视频| 午夜精品射精入后重之免费观看 | 成人免费777777被爆出| 久久亚洲国产成人精品性色| 欧洲美熟女乱又伦免费视频 | 黄色三级三级免费看| 亚洲av激情无码专区在线播放| 人妻视频一区二区三区免费| 乱爱性全过程免费视频| 亚洲特级aaaaaa毛片| 亚洲精品一级无码中文字幕 |