码迷,mamicode.com
首页 > 其他好文 > 详细

091_解析Callout XML 处理方式

时间:2020-01-19 19:02:29      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:poi   getc   amr   isp   load   dom   处理   nod   git   

XML:

<?xml version="1.0" encoding="iso-8859-1" ?>
<results>

<result>

<ip>111.93.167.67</ip>

<host />

<isp>Tata Teleservices ISP</isp>

<org>Tata Teleservices ISP</org>

<region>Calcutta</region>

<countrycode>IN</countrycode>

<latitude>22.569700241089</latitude>

<longitude>88.369697570801</longitude>

<queries>2</queries>

</result>

</results>

  

 

APEX:

public class OrgInfo_XmlStreamReader {

	public String org{get;set;}

	public List<String> XMLData{get;set;}

	public OrgInfo_XmlStreamReader(){

	   XMLData=new List<String>();

	}

 
	public List<String> getOrganisationInfo(String ip){ 

			Http http = new Http();

			HttpRequest req = new HttpRequest();

			req.setEndpoint(‘http://xml.utrace.de/?query=‘+ip);

			req.setMethod(‘GET‘);

			HttpResponse res = http.send(req);

			 

			// Log the XML content

			String xmlContent=res.getBody();

			System.debug(res.getBody());

			System.debug(‘#####XmlStreamReader ##11##‘);

			// Generate the HTTP response as an XML stream

			 

			XmlStreamReader reader = res.getXmlStreamReader();

			System.debug(‘##########XML DATA##########‘+res.getXmlStreamReader());

			 

			XMLData=XMLParser(res.getBody());

			return XMLData;

	}

 

	public List<String> XMLParser(String strXml){

		System.debug(‘####Inside XMLParser Method########‘+strXml);

		List<String> orgInfo=new List<String>();

		Dom.Document doc = new Dom.Document();

		doc.load(strXml);

		//Retrieve the root element for this document.

		Dom.XMLNode Envelope = doc.getRootElement();

		Dom.XMLNode Body= Envelope.getChildElements()[0];

		string user_createResult = ‘‘;

		 

		for(Dom.XMLNode child : Body.getChildElements()) {

		   orgInfo.add(child .getText());

		}

		return orgInfo;

	}

}

  

091_解析Callout XML 处理方式

标签:poi   getc   amr   isp   load   dom   处理   nod   git   

原文地址:https://www.cnblogs.com/bandariFang/p/12214997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!