zoukankan      html  css  js  c++  java
  • WebLoad 解析服务器返回的XML格式内容

    Parsing the XML Response

    get the root node:  var rootNode = document.wlXmls[0].XMLDocument.documentElement

    get the root node's name : rootNode.nodeName
    get the root node's first child:  var fisrtChild = rootNode.childNodes.item(0)
     
    Note: the text of a node is also a node. 
     
    Case: get the performanceId:0P0000007E of below XML Dom
    <ArrayOfPerformanceIdObjectBase>
        <PerformanceIdObjectBase>
            <PerformanceId>0P0000007E</PerformanceId>
        </PerformanceIdObjectBase>
        <PerformanceIdObjectBase>
            <PerformanceId>0P000000Q0</PerformanceId>
        </PerformanceIdObjectBase>
    </ArrayOfPerformanceIdObjectBase>
     
    function InitAgenda(){
        wlGlobals.ParseXML = true
    }
    wlHttp.GetXML
    = true; var XMLresponse = document.wlXmls[0]; var XMLDoc = XMLresponse.XMLDocument; var element = XMLDoc.documentElement; //InfoMessage("The name of the root node is: " + element.nodeName); var fisrtChildNode = element.childNodes.item(0); // get the first <PerformanceIdObjectBase> node var perfNode = fisrtChildNode.childNodes.item(0); // get the <PerformanceId> node var perfId = perfNode.childNotes.item(0).nodeValue; // get the text node and get its value:0P0000007E

    ===========================================================

    <?xml version="1.0"?>
    <res>
      <status code="0" status="0">
        <message>a_172.26.41.111:50006_1dbe4f42-acb3-ae47-9008-936faf1b0679</message>
      </status>
    </res>

    var contents = document.wlSource;
    
    var xmlObject = new XMLParserObject()
    var doc = xmlObject.parse(contents)
    
    InfoMessage(doc.getElementsByTagName("res").item(0).getChildNodes()[0].getAttribute("status"))
    
    var status = doc.getElementsByTagName("status").item(0).getAttribute("status")
    var code = doc.getElementsByTagName("status").item(0).getAttribute("code")

    以上都是取 status 这个属性

  • 相关阅读:
    初试Shell脚本
    iOS分类Category探索
    cocoaPods安装爬坑总结
    关于FFmpeg工具的使用总结
    关于Boost在工程下的配置
    关于Phabricator Arcanist以及提交项目代码
    关于visual studio的一些日常总结
    关于Python在Linux、Mac和Windows上的安装方法总结
    TextSwitcher 文本切换器的功能与用法
    Android必知必会-App 常用图标尺寸规范汇总
  • 原文地址:https://www.cnblogs.com/tomweng/p/4186228.html
Copyright © 2011-2022 走看看