<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[轉]

    ?

    一般從服務端的返回可以得到一個XML對象。
    例如服務器返回的: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?屬性,返回當前節(jié)點的屬性列表
    2 、childNodes?屬性,返回當前節(jié)點的所有子節(jié)點列表
    3 、documentElement?屬性,返回xml文件的根節(jié)點,通過Microsoft.XMLDOM對象名來調(diào)用
    4 、firstChild?屬性、lastChild?屬性,返回當前節(jié)點的第一個子(最后一個)元素(如果沒有子節(jié)點是不是返回
    第一個屬性?)
    5 、nextSibling?(previousSibling?)屬性,下一個兄弟節(jié)點。
    6 、nodeName?屬性,返回節(jié)點的標簽名字
    7 、nodeValue?屬性,傳回指定節(jié)點相關的文字(不是屬性,就是 * 號的這個內(nèi)容? **
    8 、ownerDocument?屬性,根節(jié)點
    9 、parentNode?屬性,傳回目前節(jié)點的父節(jié)點。只能應用在有父節(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é)點當作指定節(jié)點最后的子節(jié)點。
    2 、cloneNode(deep)方法,deep?是一個布爾值。如果為true,此節(jié)點會復制以指定節(jié)點發(fā)展出去的所有節(jié)
    點。如果是false,只有指定的節(jié)點和它的屬性被復制。
    3 、createAttribute(name)方法,建立一個指定名稱的屬性。
    4 、createElement?方法,建立一個指定名稱的元素。
    5 、xmlDocument.createNode(type,?name,?nameSpaceURI);type?用來確認要被建立的節(jié)點型態(tài),name?是一個字符
    串來確認新節(jié)點的名稱,命名空間的前綴則是選擇性的。nameSpaceURI?是一個定義命名空間URI?的字
    符串。如果前綴被包含在名稱參數(shù)中,此節(jié)點會在nameSpaceURI?的內(nèi)文中以指定的前綴建立。如果不
    包含前綴,指定的命名空間會被視為預設的命名空間。
    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也當做一個節(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 閱讀(392) 評論(0)  編輯  收藏 所屬分類: JavaScript

    主站蜘蛛池模板: 亚洲色欲久久久综合网东京热| 国产免费131美女视频| 亚洲欧洲无码AV电影在线观看 | 亚洲人成网站看在线播放| 久久久久成人片免费观看蜜芽 | 亚洲第一页日韩专区| 免费播放美女一级毛片| 亚洲Av无码乱码在线znlu| 日本视频免费观看| 国产亚洲美女精品久久久2020| 精品一区二区三区免费观看| 亚洲精品午夜国产VA久久成人| 很黄很污的网站免费| 亚洲av网址在线观看| 最好看最新的中文字幕免费| 色在线亚洲视频www| 国产一级一片免费播放i| 日本黄页网址在线看免费不卡| 国产成人精品久久亚洲高清不卡 | 中国国语毛片免费观看视频| 亚洲色图在线播放| 大地资源免费更新在线播放| 色吊丝免费观看网站| 久久久久亚洲AV成人无码网站| 国产麻豆视频免费观看| 亚洲av乱码一区二区三区按摩| 亚洲视频一区二区| 在线免费观看国产| 亚洲gay片在线gv网站| 亚洲一级特黄大片无码毛片| 一级毛片在线免费观看| 亚洲一本到无码av中文字幕| 亚洲欧洲日本在线| 啦啦啦完整版免费视频在线观看 | 久久大香香蕉国产免费网站| 亚洲国产精品日韩在线观看| 免费观看四虎精品国产永久| 男人的天堂网免费网站| 亚洲欧美aⅴ在线资源| 亚洲AV无码成人专区片在线观看| 成年女人免费视频播放77777|