Не могу разобраться. Есть массив, в нем строки xml формата. Второй элемент массива явно не XML, но при этом без проблем проходит валидацию. Фореч обрабатыает только первый элемент. Какие могут быть пути решения и почему 2 элемент проходит валидацию вообще не пойму. PHP: <?php $arr = array ( 1 => '<?xml version="1.0" encoding="utf-8"?> <rates> <item> <from>BTC</from> <to>SBERRUB</to> <in>1</in> <out>2145271.37253</out> <amount>19353.323805</amount> <minamount>0.005 BTC</minamount> <maxamount>0.5 BTC</maxamount> <param>manual</param> </item> <item> <from>SBERRUB</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> <item> <from>SBPbub</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> <item> <from>QWRUB</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> </rates>', 2 => '<!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]--> <!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]--> <!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]--> <head> <title>Please Wait... | Cloudflare</title> ', 3 => '<?xml version="1.0" encoding="utf-8"?> <rates> <item> <from>QWRUB</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> <item> <from>SBERRUB</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> <item> <from>SBPRUB</from> <to>BTC</to> <in>2407437.2036</in> <out>1</out> <amount>18.729196</amount> <minamount>1000 RUB</minamount> <maxamount>10000 RUB</maxamount> <param>manual</param> </item> </rates>', ); //проверка на валидацию второго значения массива $xml = XMLReader::XML($arr[2]); $xml->setParserProperty(XMLReader::VALIDATE, true); var_dump($xml->isValid()); echo "\n"; foreach($arr as $key => $value){ $course = new SimpleXMLElement($arr[$key]); //echo $course->item[0]->from . "\n"; //echo $course->item[0]->to . "\n"; foreach($course as $value){ echo $value->from . " - $key\n"; echo $value->to . " - $key\n\n"; } } print_r($course); ?>
Господа, расходимся. Нашел решение, выкладываю PHP: class XmlParser { /** * @param string $xmlFilename Path to the XML file * @param string $version 1.0 * @param string $encoding utf-8 * @return bool */ public function isXMLFileValid($xmlFilename, $version = '1.0', $encoding = 'utf-8') { $xmlContent = file_get_contents($xmlFilename); return $this->isXMLContentValid($xmlContent, $version, $encoding); } /** * @param string $xmlContent A well-formed XML string * @param string $version 1.0 * @param string $encoding utf-8 * @return bool */ public function isXMLContentValid($xmlContent, $version = '1.0', $encoding = 'utf-8') { if (trim($xmlContent) == '') { return false; } libxml_use_internal_errors(true); $doc = new DOMDocument($version, $encoding); $doc->loadXML($xmlContent); $errors = libxml_get_errors(); libxml_clear_errors(); return empty($errors); } }