Created
December 3, 2012 00:35
-
-
Save anonymous/4191809 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class BPTCallout { | |
public BPTCallout() {} | |
public static Opportunity[] parseXML(XmlStreamReader reader) { | |
Opportunity[] oppList = new List<Opportunity>(); | |
if (reader != null) { | |
while (reader.hasNext()) { | |
System.debug('$$$ reader.getEventType(): ' + reader.getEventType()); | |
if (reader.getEventType() == XmlTag.END_DOCUMENT) { | |
break; | |
} | |
else if (reader.getEventType() == XmlTag.CHARACTERS) { | |
System.debug('$$$ reader.getLocalName(): ' + reader.getLocalName()); | |
System.debug('$$$ reader.getText(): ' + reader.getText()); | |
System.debug('$$$ reader.getNamespace(): ' + reader.getNamespace()); | |
System.debug('$$$ reader.getlocation(): ' + reader.getlocation()); | |
System.debug('$$$ reader.getprefix(): ' + reader.getprefix()); | |
if (/*reader.getLocalName() == 'lname'*/ reader.getAttributeCount() == 4 && reader.getText() != null) { | |
oppList.add(new Opportunity(Name = reader.getText())); | |
} | |
} | |
reader.next(); | |
} | |
} | |
System.debug('$$$ oppList: ' + oppList); | |
return oppList; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class BPTCalloutTest { | |
private static final String XML_STR = '<document>' + | |
'<result>success</result>' + | |
'<resultcode>000000</resultcode>' + | |
'<note></note>' + | |
'<item>' + | |
'<quantity>1</quantity>' + | |
'<fname>Bob</fname>' + | |
'<lname>Tungsten</lname>' + | |
'<address>23232 Fleet Street</address>' + | |
'<city>Santa Clara</city>' + | |
'<state>CA</state>' + | |
'<zip>94105</zip>' + | |
'<country>United States</country>' + | |
'<email>blahblahblah@blahblahblah.com</email>' + | |
'<phone>4155555555</phone>' + | |
'</item>' + | |
'</document>'; | |
static testMethod void xmlStreamReaderTest() { | |
XmlStreamReader reader = new XmlStreamReader(XML_STR); | |
Opportunity[] opptyList = BPTCallout.parseXML(reader); | |
System.assert(opptyList != null); | |
System.assert(!opptyList.isEmpty()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment