小编Mos*_*sem的帖子

使用C#解析XML字符串

我需要使用C#解析一个简单的XML字符串

<items>
    <item1 value="value1" />
    <item2 value="value2" />
    <item3 value="value3" />
    <itme4 value="value4" />
    <item5 value="value5" />
    <itme6 value="value6" />
</items>
Run Code Online (Sandbox Code Playgroud)

我正在努力做到如下:

    XMLParser XMLParserObj = new XMLParser();
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xmlString);

   string item1 = xmlDoc.Attributes.GetNamedItem("item1").Value;
   string item2 = xmlDoc.Attributes.GetNamedItem("item2").Value;
   string item3 = xmlDoc.Attributes.GetNamedItem("item3").Value;
   string item4 = xmlDoc.Attributes.GetNamedItem("item4").Value;
   string item5 = xmlDoc.Attributes.GetNamedItem("item5").Value;
   string item6 = xmlDoc.Attributes.GetNamedItem("item6").Value;
Run Code Online (Sandbox Code Playgroud)

没有运气

请指教..

c# xml

4
推荐指数
2
解决办法
3万
查看次数

正则表达式以验证特殊字符集

有人请帮助生成一个正则表达式,以便使用javascript进行验证吗?除了以下字符集外,此正则表达式还应验证字母数字值:

{. - / \ ( ),'}_ + : ? ® © T
Run Code Online (Sandbox Code Playgroud)

谢谢和最好的问候..

javascript regex

2
推荐指数
1
解决办法
3805
查看次数

使用C#解析通用XML字符串

假设我有以下XML字符串:

<?xml version="1.0" encoding="utf-8" ?>
<items>
  <item1>value1</item1>
  <item2>value2</item2>
  <item3>value3</item3>
  <item4>value4</item4>
  <item5>value5</item5>
  <item6>value6</item6>
</items>
Run Code Online (Sandbox Code Playgroud)

我需要以通用的方式解析它,因为它可能会在以后更新,我不需要相应地修改我的代码.所以我尝试了以下方法:

public static Dictionary<string, string> Parser(string xmlString)
{
    Dictionary<string, string> parserDictionary = new Dictionary<string, string>();
    using (StringReader stringReader = new StringReader(xmlString))
    using (XmlTextReader reader = new XmlTextReader(stringReader))
    {
           // Parse the file and display each of the nodes.
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        parserDictionary.Add(reader.Name, reader.ReadString());
                        break;

                }
            }
    }

    return parserDictionary;      
}
Run Code Online (Sandbox Code Playgroud)

此代码有2个问题:

  1. <items>使用null值解析元素,我不需要解析它
  2. 它忽略了 <item1>

请指教

c# xml

2
推荐指数
1
解决办法
2157
查看次数

CRM 2013:从javascript调用操作

我试图使用以下函数从javascript调用操作:

function ExecuteActionCreateProject(reason, entityId, entityName, requestName)
{
    // Creating the request XML for calling the Action
    var requestXML = ""
    requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    requestXML += "  <s:Body>";
    requestXML += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
    requestXML += "      <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
    requestXML += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
    requestXML += "          <a:KeyValuePairOfstringanyType>";
    requestXML += "            <b:key>Reason</b:key>";
    requestXML += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">"+reason+"</b:value>";
    requestXML += "          </a:KeyValuePairOfstringanyType>";
    requestXML += "          <a:KeyValuePairOfstringanyType>";
    requestXML += "            <b:key>Target</b:key>";
    requestXML += "            <b:value i:type=\"a:EntityReference\">";
    requestXML += "              <a:Id>"+entityId+"</a:Id>";
    requestXML …
Run Code Online (Sandbox Code Playgroud)

crm dynamics-crm dynamics-crm-2011

2
推荐指数
1
解决办法
7522
查看次数

CRM 2013:在自定义工作流活动中使用选项集输入参数的值

我试图在自定义工作流活动中使用optionset输入参数,所以我使用了以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using System.Globalization;

namespace ITWorx.VisitManagement.Workflows
{
    public class FormatDate : CodeActivity
    {
        [Input("Preferred Language")]
        [AttributeTarget("contact", "itworx_preferredlanguage")]
        [Default("894330000")]
        public InArgument<OptionSetValue> PreferredLanguage { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);

            int preferredLanguage = PreferredLanguage.Get<OptionSetValue>(context).Value;

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在下面的行中抛出了一个异常:

int preferredLanguage = PreferredLanguage.Get<OptionSetValue>(context).Value;
Run Code Online (Sandbox Code Playgroud)

异常:NullReferenceException {"对象引用未设置为对象的实例."}

请指教

c# crm dynamics-crm dynamics-crm-2013

0
推荐指数
1
解决办法
8823
查看次数