Docusign XML C#LINQ枚举没有产生任何结果

时间:2014-11-18 23:34:20

标签: c# xml linq docusignapi

我在Docusign上使用Rest v2 API。我正在返回特定envelopeId的信封状态。我的想法是将数据返回到一个匿名变量,其中集合中的每个元素都可以单独访问。下一步是在C#中为我需要的特定数据创建类。

但我真正需要的是每个签名者在特定信封上的状态。

我在使用C#中的linq尝试解析以下XML时遇到了麻烦。基于下面的XML,我将如何构造我的linq查询以从XML返回数据?我已经尝试了下面的linq代码的许多不同的咒语,似乎没有任何工作。

我得到“枚举没有结果”

我对一个完全不同的解决方案持开放态度。我只是想显示给定信封的签名者的当前状态。

C#代码在

之下
            HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(webResponse.GetResponseStream());

            XmlDocument xDoc = new XmlDocument();  

                var xdoc = XDocument.Load(sr);
            var units = from u in xdoc.Descendants("signers")
                        select new
                        {
                            eventTimestamp = (int)u.Element("eventTimestamp"),
                            status = (string)u.Element("status")
                        };

            foreach (var unit in units)
            {


                _alltext += "eventTimestamp = " + unit.eventTimestamp + " status = " + unit.status;

            }

以下是我从Docusign获得的XML响应

    <recipients xmlns="http://www.docusign.com/restapi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <agents>
    <carboncopies>
      <carboncopy>
        <note>
          <recipientid>3</recipientid>
          <recipientidguid>8efddbdb-7b2b-4ecf-8162-c61a74569bb3</recipientidguid>
          <requireidlookup>false</requireidlookup>
          <rolename>Imaging Mailbox</rolename>
          <routingorder>3</routingorder>
          <status>created</status>
          <templatelocked>true</templatelocked>
          <templaterequired>true</templaterequired>
          <userid>0950b93c-9e9f-4c09-9631-55a7c6316452</userid>
          <email>sean.tori@21st.com</email>
          <name>Imaging Mailbox</name>
        </note>
      </carboncopy>
    </carboncopies>
    <certifieddeliveries>
      <currentroutingorder>1</currentroutingorder>
      <editors>
        <inpersonsigners>
          <intermediaries>
            <recipientcount>3</recipientcount>
            <signers>
              <signer>
                <note>
                  <recipientid>2</recipientid>
                  <recipientidguid>962a8552-c9f3-4715-b4ae-73d4e85dfbab</recipientidguid>
                  <requireidlookup>false</requireidlookup>
                  <rolename>Approval Queue</rolename>
                  <routingorder>2</routingorder>
                  <status>created</status>
                  <templatelocked>true</templatelocked>
                  <templaterequired>true</templaterequired>
                  <userid>e34d0005-8a19-494f-be6b-04b58f50254d</userid>
                  <email>sean.tori@21st.com</email>
                  <name>Any Signer</name>
                  <tabs>
                    <approvetabs>
                      <approve>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>2</recipientid>
                        <tabid>e1038387-cad5-4220-b279-6ac24e248ef5</tabid>
                        <xposition>473</xposition>
                        <yposition>88</yposition>
                        <font>arial</font>
                        <fontsize>size9</fontsize>
                        <tablabel>Approve 1</tablabel>
                        <buttontext>Approve</buttontext>
                        <height>22</height>
                        <width>54</width>
                      </approve>
                    </approvetabs>
                    <declinetabs>
                      <decline>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>2</recipientid>
                        <tabid>4ed56261-b86a-4fc5-9a31-f72f2cac6b7a</tabid>
                        <xposition>472</xposition>
                        <yposition>116</yposition>
                        <font>arial</font>
                        <fontsize>size9</fontsize>
                        <tablabel>Decline 1</tablabel>
                        <buttontext>Decline</buttontext>
                        <declinereason>
                          <height>22</height>
                          <width>51</width>
                        </declinereason>
                      </decline>
                    </declinetabs>
                  </tabs>
                </note>
              </signer>
              <signer>
                <note>
                  <recipientid>1</recipientid>
                  <recipientidguid>2706d282-2145-48f2-a193-ca2af01da395</recipientidguid>
                  <requireidlookup>false</requireidlookup>
                  <rolename>Customer</rolename>
                  <routingorder>1</routingorder>
                  <status>sent</status>
                  <templatelocked>false</templatelocked>
                  <templaterequired>true</templaterequired>
                  <userid>68d684cb-75d7-4e6d-8182-42afbc075faa</userid>
                  <email>jesse@ejhost.com</email>
                  <name>MARVIN HANSFORD</name>
                  <tabs>
                    <checkboxtabs>
                      <checkbox>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>2c538f0a-4cae-4188-b561-9274436d9405</tabid>
                        <xposition>111</xposition>
                        <yposition>300</yposition>
                        <locked>false</locked>
                        <required>false</required>
                        <name>Checkbox</name>
                        <requireinitialonsharedchange>false</requireinitialonsharedchange>
                        <selected>true</selected>
                        <shared>false</shared>
                        <tablabel>Check Box 5</tablabel>
                      </checkbox>
                      <checkbox>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>67a6c199-a194-410e-aab2-7be88b51a944</tabid>
                        <xposition>111</xposition>
                        <yposition>327</yposition>
                        <locked>false</locked>
                        <required>false</required>
                        <name>Checkbox</name>
                        <requireinitialonsharedchange>false</requireinitialonsharedchange>
                        <selected>true</selected>
                        <shared>false</shared>
                        <tablabel>Check Box 6</tablabel>
                      </checkbox>
                      <checkbox>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>68392379-c682-4874-90d8-22b5a4acac99</tabid>
                        <xposition>111</xposition>
                        <yposition>351</yposition>
                        <locked>false</locked>
                        <required>false</required>
                        <name>Checkbox</name>
                        <requireinitialonsharedchange>false</requireinitialonsharedchange>
                        <selected>true</selected>
                        <shared>false</shared>
                        <tablabel>Check Box 7</tablabel>
                      </checkbox>
                    </checkboxtabs>
                    <datesignedtabs>
                      <datesigned>
                        <documentid>1</documentid>
                        <pagenumber>2</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>c048b6cb-9122-458a-807d-e3464032f6a6</tabid>
                        <xposition>420</xposition>
                        <yposition>561</yposition>
                        <tablabel>Date Signed</tablabel>
                        <name>Date Signed</name>
                        <value></value>
                      </datesigned>
                    </datesignedtabs>
                    <fullnametabs>
                      <fullname>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>6221dc03-410a-4525-829b-28aa5c86e12c</tabid>
                        <xposition>185</xposition>
                        <yposition>177</yposition>
                        <tablabel>Full Name</tablabel>
                        <name>Full Name</name>
                      </fullname>
                    </fullnametabs>
                    <signheretabs>
                      <signhere>
                        <documentid>1</documentid>
                        <pagenumber>2</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>2fb6a368-94e0-44fa-8bdb-df45d4806870</tabid>
                        <xposition>135</xposition>
                        <yposition>518</yposition>
                        <name>Sign Here</name>
                        <optional>false</optional>
                        <scalevalue>1</scalevalue>
                        <tablabel>Signature 3</tablabel>
                      </signhere>
                    </signheretabs>
                    <texttabs>
                      <text>
                        <documentid>1</documentid>
                        <pagenumber>1</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>8e76581a-d189-4404-a3a0-4a7a5d34a296</tabid>
                        <xposition>184</xposition>
                        <yposition>195</yposition>
                        <font>arial</font>
                        <fontcolor>black</fontcolor>
                        <fontsize>size9</fontsize>
                        <tablabel>lblPolicyNumber</tablabel>
                        <concealvalueondocument>false</concealvalueondocument>
                        <disableautosize>false</disableautosize>
                        <locked>true</locked>
                        <maxlength>8</maxlength>
                        <name>Policy Number</name>
                        <required>false</required>
                        <value>7868169</value>
                        <width>60</width>
                        <requireinitialonsharedchange>false</requireinitialonsharedchange>
                        <shared>false</shared>
                        <validationmessage>
                          <validationpattern>
                            <height>22</height>
                            <ispaymentamount>false</ispaymentamount>
                          </validationpattern>
                        </validationmessage>
                      </text>
                      <text>
                        <documentid>1</documentid>
                        <pagenumber>2</pagenumber>
                        <recipientid>1</recipientid>
                        <tabid>431bdf22-8f3d-4afd-a4b7-6e68a8df3a02</tabid>
                        <xposition>23</xposition>
                        <yposition>750</yposition>
                        <font>arial</font>
                        <fontcolor>black</fontcolor>
                        <fontsize>size9</fontsize>
                        <tablabel>lblPolicyNumberBottom</tablabel>
                        <concealvalueondocument>false</concealvalueondocument>
                        <disableautosize>true</disableautosize>
                        <locked>true</locked>
                        <name>Policy Number</name>
                        <required>false</required>
                        <value>
                          <width>78</width>
                          <requireinitialonsharedchange>false</requireinitialonsharedchange>
                          <shared>false</shared>
                          <validationmessage>
                            <validationpattern>
                              <height>22</height>
                              <ispaymentamount>false</ispaymentamount>
                            </validationpattern>
                          </validationmessage>
                        </value>
                      </text>
                    </texttabs>
                  </tabs>
                </note>
              </signer>
            </signers>
          </intermediaries>
        </inpersonsigners>
      </editors>
    </certifieddeliveries>
  </agents>
</recipients>

1 个答案:

答案 0 :(得分:0)

您是否看过DocuSign在其开发人员中心提供的9 API Walkthroughs?有一个专门用于检索给定信封上的各个收件人状态,而C#代码示例使用xml格式而不是json,因此您可以使用示例XML解析代码 - 是。

我特别提及的API演练称为获取信封收件人状态,可在此处找到:

http://iodocs.docusign.com/APIWalkthrough/getEnvelopeRecipientStatus

这是示例使用的XML解析代码......

//////////////////////////////////////////////////////////////////////////////////////////////////
public static string parseDataFromResponse(string response, string searchToken)
{
    // look for "searchToken" in the response body and parse its value
    using (XmlReader reader = XmlReader.Create(new StringReader(response))) {
        while (reader.Read()) {
            if((reader.NodeType == XmlNodeType.Element) && (reader.Name == searchToken))
                return reader.ReadString();
        }
    }
    return null;
}