Чтение xml-данных с url с использованием curl и php

Я хочу прочитать XML-данные из URL-адреса. У меня есть URL-адрес, как следует

http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A

Вот мой код

$Url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A"; if (!function_exists('curl_init')){ die('Sorry cURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $Url); $output = curl_exec($ch); $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Close the cURL resource, and free system resources curl_close($ch); 

Может ли кто-нибудь рассказать мне, как читать XML-данные?

Благодаря…..

Вот пример кода (модуль XML-анализа может быть недоступен при установке PHP):

 <?php $url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); print_r($xml) ?> 

Переменная $xml теперь представляет собой многомерный массив значений ключа, и вы должны легко понять, как получить элементы оттуда.

try {URL url = новый URL (" http://durgajobs.com/Bangalore.html ");

  URLConnection con=url.openConnection(); int x=0; while(true) { x=con.getInputStream().read(); if(x==-1) { break; } System.out.print((char)x); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } в  URLConnection con=url.openConnection(); int x=0; while(true) { x=con.getInputStream().read(); if(x==-1) { break; } System.out.print((char)x); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

Мне нужен тот же код в php

 // the SAX way: XMLReader myReader = XMLReaderFactory.createXMLReader(); myReader.setContentHandler(handler); myReader.parse(new InputSource(new URL(url).openStream())); // or if you prefer DOM: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new URL(url).openStream()); 

Это демонстрация того, как получить идентификатор канала из rss-канала youtube, в котором я читаю xml-данные из url, используя curl.

 $channel_id = 'XXXXXXXX'; // put the channel id here //using curl $url = 'https://www.youtube.com/feeds/videos.xml?channel_id='.$channel_id.'&orderby=published'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); $response = curl_exec($ch); curl_close($ch); $response=simplexml_load_string($response); $json = json_encode($response); $youtube= json_decode($json, true); $count = 0; if(isset($youtube['entry']['0']) && $youtube['entry']['0']!=array()) { foreach ($youtube['entry'] as $k => $v) { $yt_vids[$count]['id'] = str_replace('http://www.youtube.com/watch?v=', '', $v['link']['@attributes']['href']); $yt_vids[$count]['title'] = $v['title']; $count++; } } else { $yt_vids[$count]['id']=str_replace('http://www.youtube.com/watch?v=', '', $youtube['entry']['link']['@attributes']['href']); $yt_vids[$count]['title']=$youtube['title']; } echo "<pre>"; print_r($yt_vids); 
 try { URL url=new URL("https://www.freshers-job.com/"); URLConnection con=url.openConnection(); int x=0; while(true) { x=con.getInputStream().read(); if(x==-1) { break; } System.out.print((char)x); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } в try { URL url=new URL("https://www.freshers-job.com/"); URLConnection con=url.openConnection(); int x=0; while(true) { x=con.getInputStream().read(); if(x==-1) { break; } System.out.print((char)x); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }