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
<?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;
}
Related Posts
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…33Sylvester