Get XML Element By Tag Name using C#

1
I was working with creating a job using the SalesForce Bulk API
and i needed to get the JobId from API Response

<?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>

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


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

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I agree to have my personal information transfered to Mad Mimi ( more information )

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

1 thought on “Get XML Element By Tag Name using C#

  1. I must say it was hard to find your page in search results.
    You write great posts but you should rank your blog higher
    in search engines.
    33Sylvester recently posted…33SylvesterMy Profile

Leave a Reply

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

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.