我正在尝试从URL获取XML文件。 但我只得到文件中的文字,没有语法。
我的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://services.mobile.de/search-api/search?country=DE&sort.field=makeModel&sort.order=ASCENDING');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '. base64_encode("username:password"), 'Accept:
application/xml'));
$xml = new SimpleXMLElement(curl_exec($ch));//line 14
curl_close($ch);
print_r($xml);
我的输出:
....sensorsBlackEuro5PetrolManual gearboxAutomatic air conditioningUsed vehicle150.90525114.812090CarSmall CarVolkswagenPoloCentral lockingElectric windowsImmobilizerPower Assisted SteeringABSESPFull Service HistoryElectric side mirrorOn-board computerCD playerTuner/radioIsofix (child seat anchor points)Parking sensor
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 14
Warning: SimpleXMLElement::__construct(): 1 in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 14
Warning: SimpleXMLElement::__construct(): ^ in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 14
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Applications/XAMPP/xamppfiles/htdocs/test.php:14 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/test.php(14): SimpleXMLElement->__construct('1') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 14
更新
我现在在浏览器中找到正确的字符串:
echo '<pre>';
echo htmlspecialchars(print_r(curl_exec($ch), true));
echo '</pre>';
但是当我尝试使用时:
$sxe = simplexml_load_string($re);
print_r($sxe);
我只能得到这个:
SimpleXMLElement Object ( )
答案 0 :(得分:1)