function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NewToSFNewToSF 

Parse XML in Apex

Hi,
 
  I am getting XML string from websrvice call. I want to parse that and update the custom object. I don't know how to parse the string like below.
 
<outloop status='success'><innerloop><value id='1242'></value></innerloop><error></error></outloop>
 
Pls. help.
 
Thanks,
 
cheenathcheenath
You can use XmlStreamReader class in Apex. Details here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_XmlStream_reader.htm


HTHs,

Ron HessRon Hess
XML stream reader is quite powerful, i've posted an example of using stream reader to implement a simple XML DOM parser, you can find this code located on force.com code share :

http://code.google.com/p/visualforce-components/source/browse/trunk/XmlDom/src/unpackaged/classes/XMLDom.cls

enjoy!
ShaamboShaambo
thank you ron that was really helpful.
Jim BoudreauxJim Boudreaux

pardon my ignorance, but could someone please explain how to use the XMLStreamReader to extract Contact info from the following xml string and put it into a contact object?

 

 

<contact>
  <name part="last">Smith</name>
  <name part="first">John</name>
  <email>jsmith@gmail.com</email>
  <phone type="mobile">6785557867</phone>
</contact>

 I can't figure out how to extract the text from an element of a specific attribute value, like <name> where part = 'last' so I can then assign that to contact.lastname