这是我无法解析的 XML SOAP 响应的一部分:
<soap:Envelope><soap:Body><getTrainScheduleXMLResponse><getTrainScheduleXMLResult><STATION><STATION_2CHAR>NY</STATION_2CHAR><STATIONNAME>New York Penn Station</STATIONNAME><ITEMS><ITEM><ITEM_INDEX>0</ITEM_INDEX><SCHED_DEP_DATE>18:08:00 06/10/2013</SCHED_DEP_DATE><DESTINATION>MSU</DESTINATION><TRACK>6</TRACK><LINE>MNBTN</LINE><TRAIN_ID>6279</TRAIN_ID><STATUS>ALL ABOARD</STATUS><BACKCOLOR>brown</BACKCOLOR><FORECOLOR>white</FORECOLOR><SHADOWCOLOR>black</SHADOWCOLOR><GPSLATITUDE/><GPSLONGITUDE/><GPSTIME>6/10/2013 5:45:30 PM</GPSTIME><TRAIN_LINE>Montclair-Boonton Line</TRAIN_LINE><STATION_POSITION>0</STATION_POSITION><LINEABBREVIATION>MNBTN</LINEABBREVIATION><INLINEMSG/><STOPS><STOP><NAME>Newark Broad Street</NAME><TIME>6/10/2013 6:25:00 PM</TIME></STOP><STOP><NAME>Watsessing Avenue</NAME><TIME>6/10/2013 6:31:30 PM</TIME></STOP><STOP><NAME>Bloomfield</NAME><TIME>6/10/2013 6:34:00 PM</TIME></STOP><STOP><NAME>Glen Ridge</NAME><TIME>6/10/2013 6:36:30 PM</TIME></STOP><STOP><NAME>Bay Street</NAME><TIME>6/10/2013 6:39:30 PM</TIME></STOP><STOP><NAME>Walnut Street</NAME><TIME>6/10/2013 6:43:00 PM</TIME></STOP><STOP><NAME>Watchung Avenue</NAME><TIME>6/10/2013 6:45:30 PM</TIME></STOP><STOP><NAME>Upper Montclair</NAME><TIME>6/10/2013 6:48:30 PM</TIME></STOP><STOP><NAME>Mountain Avenue</NAME><TIME>6/10/2013 6:51:00 PM</TIME></STOP><STOP><NAME>Montclair Heights</NAME><TIME>6/10/2013 6:53:30 PM</TIME></STOP><STOP><NAME>Montclair State U</NAME><TIME>6/10/2013 6:59:00 PM</TIME></STOP></STOPS></ITEM>
我试过这样做:
$xmlstr = file_get_contents("data.xml");
$xml = new SimpleXMLElement($xmlstr);
var_dump($xml);
但它返回以下输出:
object(SimpleXMLElement)#1 (0) {
}
我认为它是空的?如何在 PHP 中解析这个 XML?这不是提供的完整文件。谢谢!