zoukankan      html  css  js  c++  java
  • CRM2011 读取fetch 查询返回的xml

    View Code
    View Code
    /*
    *根据属性名称读取属性值
    */
    function GetAttributeValue(entityNode, attrName) {
    
        var attributes = entityNode.selectNodes('//a:KeyValuePairOfstringanyType')
        for (var i = 0; i < attributes.length; i++) {
            var key = attributes[i].selectSingleNode('b:key').text;
            if (key == attrName) {
                var attribute = attributes[i];
                var itype = attribute.selectSingleNode('b:value').getAttribute('i:type')
                switch (itype) {
                    case 'a:EntityReference':
                        return {
                            Id: attribute.selectSingleNode('b:value/a:Id').text,
                            LogicalName: attribute.selectSingleNode('b:value/a:LogicalName').text,
                            Name: attribute.selectSingleNode('b:value/a:Name').text
                        };
                        break;
                    case 'a:OptionSetValue':
                        return {
    
                            Value: attribute.selectSingleNode('//a:Value').text
                        };
                        break;
                    default:
    
                }
            }
    
        }
    }

     昨天测试完后对代码做了一些调整,补充一些default

    /*
    *根据属性名称读取属性值
    */
    function GetAttributeValue(entityNode, attrName) {
    
        var attributes = entityNode.selectNodes('//a:KeyValuePairOfstringanyType')
        for (var i = 0; i < attributes.length; i++) {
            var key = attributes[i].selectSingleNode('b:key').text;
            if (key == attrName) {
                var attribute = attributes[i];
                var itype = attribute.selectSingleNode('b:value').getAttribute('i:type')
                switch (itype) {
                    case 'a:EntityReference':
                        return {
                            Id: attribute.selectSingleNode('b:value/a:Id').text,
                            LogicalName: attribute.selectSingleNode('b:value/a:LogicalName').text,
                            Name: attribute.selectSingleNode('b:value/a:Name').text
                        };
                        break;
                    case 'a:OptionSetValue':
                        return {
    
                            Value: attribute.selectSingleNode('//a:Value').text
                        };
                        break;
                    default:
                        return attribute.selectSingleNode('b:value').text;
                        break;
    
    
                }
            }
    
        }
    }
    <a:Entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
    <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <a:KeyValuePairOfstringanyType>
    <b:key>new_backupid</b:key>
    <b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">e27f1c40-7ffc-e111-90d0-00155d77394d</b:value>
    </a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>new_account_new_backup_id</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:EntityReference"><a:Id>091d12c9-cec4-e111-ab5c-00155d77394d</a:Id><a:LogicalName>account</a:LogicalName><a:Name>ACE Life Insurance Company Limited</a:Name></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>new_type</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:OptionSetValue"><a:Value>100000000</a:Value></b:value></a:KeyValuePairOfstringanyType>
    <a:KeyValuePairOfstringanyType><b:key>new_systemuser_new_backup_id</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:EntityReference"><a:Id>a0534b18-b5c4-e111-ab5c-00155d77394d</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name>方力</a:Name></b:value></a:KeyValuePairOfstringanyType></a:Attributes><a:EntityState xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:nil="true"/><a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringstring>
    <b:key>new_type</b:key><b:value>临分个险核保A</b:value></a:KeyValuePairOfstringstring></a:FormattedValues><a:Id>e27f1c40-7ffc-e111-90d0-00155d77394d</a:Id>
    <a:LogicalName>new_backup</a:LogicalName>
    <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
    </a:Entity>
  • 相关阅读:
    HDU 2236 无题Ⅱ
    Golden Tiger Claw(二分图)
    HDU 5969 最大的位或 (思维,贪心)
    HDU 3686 Traffic Real Time Query System (图论)
    SCOI 2016 萌萌哒
    Spring Boot支持控制台Banner定制
    构建第一个Spring Boot程序
    Spring Boot重要模块
    Java fastjson JSON和String互相转换
    BCompare 4 Windows激活方法【试用期30天重置】
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2681817.html
Copyright © 2011-2022 走看看