需要从xml获取节点值

时间:2014-11-26 04:16:11

标签: javascript xml soap dynamics-crm-2011 dynamics-crm

我使用以下代码通过使用SOAP Services获取Id。我得到了Xml响应,因为它工作正常。

    function guid(){

    var xml = "<?xml version='1.0' encoding='utf-8'?>" + 
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
        GenerateAuthenticationHeader() +
        "<soap:Body>" + 
        "<RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
        "<query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
        "<q1:EntityName>opportunity</q1:EntityName>" + 
        "<q1:ColumnSet xsi:type='q1:ColumnSet'>" + 
        "<q1:Attributes>" + 
        "<q1:Attribute>opportunityid</q1:Attribute>" +
        "</q1:Attributes>" + 
        "</q1:ColumnSet>" + 
        "<q1:Distinct>false</q1:Distinct>" + 
        "</query></RetrieveMultiple>" +
        "</soap:Body></soap:Envelope>";

        var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
       // xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);

        var result = xmlHttpRequest.responseXML.xml;
        var doc = new ActiveXObject("MSXML2.DOMDocument");
        doc.async = false;
        doc.load(result);


    }

响应是:

enter image description here

我需要使用javascript从结果xml中获取?

1 个答案:

答案 0 :(得分:0)

以这种方式加载Xml:

doc.loadXML(xmlHttpRequest.responseXML.text);