Get XML Element By Tag Name using C#

I was working with creating a job using the SalesForce Bulk API
and i needed to get the JobId from API Response
[code]
<?xml version="1.0" encoding="UTF-8"?>
<jobInfo
xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<id>12345678903AAK</id>
<operation>query</operation>
<object>Contact</object>
<createdById>1234567890AAA</createdById>
<createdDate>2012-08-30T10:04:45.000Z</createdDate>
<systemModstamp>2012-08-30T10:04:45.000Z</systemModstamp>
<state>Open</state>
<concurrencyMode>Parallel</concurrencyMode>
<contentType>CSV</contentType>
<numberBatchesQueued>0</numberBatchesQueued>
<numberBatchesInProgress>0</numberBatchesInProgress>
<numberBatchesCompleted>0</numberBatchesCompleted>
<numberBatchesFailed>0</numberBatchesFailed>
<numberBatchesTotal>0</numberBatchesTotal>
<numberRecordsProcessed>0</numberRecordsProcessed>
<numberRetries>0</numberRetries>
<apiVersion>24.0</apiVersion>
<numberRecordsFailed>0</numberRecordsFailed>
<totalProcessingTime>0</totalProcessingTime>
<apiActiveProcessingTime>0</apiActiveProcessingTime>
<apexProcessingTime>0</apexProcessingTime>
</jobInfo>
[/code]

Use following function to get the Job Id by passing in the XML

[code]
private string GetID(string xmlString)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
XmlNodeList node = doc.GetElementsByTagName("id");
return node.Item(0).InnerText;
}
[/code]

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Comments (1)
  1. 33Sylvester May 17, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge