Docusign XML C# LINQ 枚举未产生任何结果
本文关键字:任何 结果 枚举 XML LINQ Docusign | 更新日期: 2023-09-27 18:30:49
我在Docusign上使用Rest v2 API。我正在返回特定信封 ID 的信封状态。我的想法是将数据返回到一个匿名变量中,其中集合中的每个元素都可以单独访问。下一步将是用 C# 为我需要的特定数据创建类。
但实际上,我所需要的只是特定信封上每个签名者的状态。
我在尝试使用 C# 中的 linq 解析以下 XML 时遇到问题。基于下面的 XML,我将如何构造我的 linq 查询以从 XML 返回数据?我已经尝试了下面 linq 代码的许多不同的咒语,但似乎没有任何效果。
我得到"枚举没有结果"
我对一个完全不同的解决方案持开放态度。我只是想显示给定信封 ID 的签名者的当前状态。
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>
您是否看过 DocuSign 在其开发人员中心提供的 9 个 API 演练? 有一个专门设计用于检索给定信封上的单个收件人状态,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;
}