• 091_解析Callout XML 处理方式


    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;
    
    	}
    
    }
    

      

    此刻,静下心来学习
  • 相关阅读:
    c# 判断一个ip通不通 能不能ping通
    C#二进制与字符串互转换,十六进制转换为字符串、float、int
    将datagridview数据保为xml或txt文件
    笨办法学Python(九)
    笨办法学Python(八)
    笨办法学Python(七)
    Linux安装 NTFS 支持
    Linux安装中文字体包
    Oracle VM VirtualBox 共享文件夹设置
    Verilog频率计设计
  • 原文地址:https://www.cnblogs.com/bandariFang/p/12214997.html
Copyright © 2020-2023  润新知