jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes Multiple URL access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Multiple URL access" Watch "Multiple URL access" New topic
Author

Multiple URL access

Durga Roobini
Ranch Hand

Joined: Dec 19, 2013
Posts: 105
How to open multiple http connections based on client request
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
What does this have to with XML (which this forum is all about)?

But I don't understand the question. Assuming you're talking about URLConnection, HttpClient or some such approach - what difficulty do you see in opening multiple connections?


Ping & DNS - my free Android networking tools app
Durga Roobini
Ranch Hand

Joined: Dec 19, 2013
Posts: 105
I post my codings here,What am doing here is I access third party webservices(eventful) and parsed xml in servlet and in jsp page I gave location means it will retrieve events types and month so I got expected output but now what I want to do is,i have two more url like eventful,eventbrite,eventforce like this I want parse xml for this url,but I don't want to repeat codings by changing url ,here I want to parse only once how I implement this one

try{
URL url = new URL("http://api.eventful.com/v1/jobsearch?DeveloperKey=WDH36716NGKGL3VVCDN8&locationcity="+loc);
URLConnection uconn=url.openConnection();
HttpURLConnection conn=(HttpURLConnection)uconn;
conn.connect();
Object content=conn.getContent();
InputStream stream=(InputStream) content;
DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder();
Document doc=docBuilder.parse(stream);
doc.getDocumentElement().normalize();
str.append("<career>");
NodeList joblist=doc.getElementsByTagName("JobSearchResult");
for(int i=0;i<joblist.getLength();i++)
{
Node job=joblist.item(i);
if(job.getNodeType()== Node.ELEMENT_NODE){
Element firstPersonElement=(Element)job;
NodeList companytag=firstPersonElement.getElementsByTagName("title");
Element com_name=(Element)companytag.item(0);
NodeList textComList=com_name.getChildNodes();
NodeList titletag = firstPersonElement.getElementsByTagName("month");
Element title_name = (Element) titletag.item(0);
NodeList textTitleList = title_name.getChildNodes();

NodeList didtag = firstPersonElement.getElementsByTagName("DID");
Element did_text = (Element) didtag.item(0);
NodeList textDidList = did_text.getChildNodes();


String title = ((Node) textTitleList.item(0)).getNodeValue().replaceAll("&","a");
String company = ((Node) textComList.item(0)).getNodeValue().replaceAll("&","a");
String did = ((Node) textDidList.item(0)).getNodeValue().replaceAll("&","a");
// str.append("<br>"+title+"<br>"+company+"<br>"+did);
str.append("<results>");
str.append("<jobtitle>");
str.append(company);
str.append(title);
str.append("</jobtitle>");
str.append("<company>");
str.append(company);
str.append("</company>");
str.append("<jobid>");
str.append(did);
str.append("</jobid>");
str.append("</results>");
str.append("</career>");
}
}



}catch(Exception e){
System.out.println(e);

}
//str.append("</career>");
// out.println(str.toString());
String data=str.toString();
response.getWriter().write(data.toString());



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Not following. If you want to access 3 different servers, then you'll have to have code to do that. You might be able to factor out the mechanics of doing the HTTP access into common code, but the XML part will obviously depend a lot on what the server returns.

I take it that's what you're asking in http://www.coderanch.com/t/626428/XML/Parse-Multiple-Xml-files-structure?
Durga Roobini
Ranch Hand

Joined: Dec 19, 2013
Posts: 105
Ya three different xml is there but I want transform it and make single xml file,it should me generic for all API how to implement this one
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
So what, exactly, is the problem you're facing? Designing an XML format that you can use the store the results of 3 different XML formats? And then transforming those 3 formats into the unified format?
Durga Roobini
Ranch Hand

Joined: Dec 19, 2013
Posts: 105
Ya Exactly thanks for understanding my problem give some idea or samples or links please
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
I don't know that anyone here can help with that, because we know neither the format of the files, nor do we have any idea what the purpose of the target format is. In the simplest case, you can just concatenate the source files (given the result a new root element. of course, and only a single XML declaration).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple URL access