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>
  • 相关阅读:
    POJ 2756 Autumn is a Genius 大数加减法
    RoboGuice注入框架简单应用
    Android 从相冊获取近期拍摄的多张照片(获取相机拍照所存储的照片)
    不可不知的DIP、IoC、DI以及IoC容器
    Codeforces Round #156 (Div. 2)---A. Greg&#39;s Workout
    zend framework将zip格式的压缩文件导入并解压到指定文件
    TreeSet排序
    Bee Framework_百度百科
    duck
    anglehack参赛总结
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2681817.html
Copyright © 2011-2022 走看看