Apex Class
Test Class
- public class XMLParsing{
- Public void parseXML(String xmlfile)
- {
- DOM.Document xmlDOC = new DOM.Document();
- xmlDOC.load(xmlfile);
- DOM.XMLNode rootElement = xmlDOC.getRootElement();
- System.Debug('$$$$ Root Element'+rootelement);
- for(DOM.XMLNode xmlNodeObj:xmlDOC.getRootElement().getChildElements()){
- System.Debug('$$$ Child Elements'+xmlNodeObj);
- for(DOM.XMLNode xmlNodeObjChild:xmlNodeObj.getChildren())
- {
- System.Debug('$$$ Childrens'+xmlNodeObjChild.getChildren());
- if(xmlNodeObjChild.getName()=='FirstName')
- System.Debug(xmlNodeObjChild.getText());
- if(xmlNodeObjChild.getName()=='Email')
- System.Debug(xmlNodeObjChild.getText());
- if(xmlNodeObjChild.getName()=='Phone')
- System.Debug(xmlNodeObjChild.getText());
- if(xmlNodeObjChild.getName()=='ReasonforContactString')
- System.Debug(xmlNodeObjChild.getText());
- }
- }
- }
- }
Test Class
- @isTest
- public class TestXMLParser
- {
- static testMethod void testXmlParser() {
- XMLParsing a=new XMLParsing();
- String str = '<AptiLeads><lead><FirstName>Arunkumar</FirstName><LastName>R</LastName><Email>arun@gmail..com</Email><Phone>7777777777</Phone><ReasonforContact>Associate of Arts in Business</ReasonforContact></lead><lead><FirstName>Balaji</FirstName><LastName>Ram</LastName><Email>ram@gmail.com</Email><Phone>999999991</Phone><ReasonforContact>Associate of Arts in Busines1s</ReasonforContact></lead></AptiLeads>';
- a.parseXML(str);
- }
- }