괜찮습니다. 이것이 나를 미치게합니다.
XML 파일을 특정 배열이나 개체로 구문 분석하려고 했으므로 유사한 파일과 비교하여 차이점을 테스트 할 수 있습니다.
그러나 나는 운이 없었습니다. 나는 이것을하기 위해 SimpleXMLIterator와 SimpleXMLElement를 사용하려고 시도해왔다.
다음은 몇 가지 샘플입니다 : 여기 비교를 위해 Xml 파일을 구문 분석하십시오.
<xml>
//This is the first record of 1073
<viddb>
<movies>1074</movies>
<movie>
<title>10.5</title>
<origtitle>10.5</origtitle>
<year>2004</year>
<genre>Disaster</genre>
<release></release>
<mpaa></mpaa>
<director>John Lafia</director>
<producers>Howard Braunstein, Jeffrey Herd</producers>
<actors>Kim Delaney, Fred Ward, Ivan Sergei</actors>
<description>An earthquake reaching a 10.5 magnitude on the Richter scale, strikes the west coast of the U.S. and Canada. A large portion of land falls into the ocean, and the situation is worsened by aftershocks and tsunami.</description>
<path>E:\www\Media\Videos\Disaster\10.5.mp4</path>
<length>164</length>
<size>3648</size>
<resolution>640x272</resolution>
<framerate>29.97</framerate>
<videocodec>AVC</videocodec>
<videobitrate>2966</videobitrate>
<label>Roku Media</label>
<poster>images/10.5.jpg</poster>
</movie>
이 레코드를 사용하여 생산하는 객체이다
$iter = new SimpleXMLIterator($xml, 0, TRUE);
object(SimpleXMLIterator)#71 (1) {
["viddb"] => object(SimpleXMLIterator)#72 (2) {
["movies"] => string(4) "1074"
["movie"] => array(1074) {
[0] => object(SimpleXMLIterator)#73 (19) {
["title"] => string(4) "10.5"
["origtitle"] => string(4) "10.5"
["year"] => string(4) "2004"
["genre"] => string(8) "Disaster"
["release"] => object(SimpleXMLIterator)#1158 (0) {
}
["mpaa"] => object(SimpleXMLIterator)#1159 (0) {
}
["director"] => string(10) "John Lafia"
["producers"] => string(31) "Howard Braunstein, Jeffrey Herd"
["actors"] => string(35) "Kim Delaney, Fred Ward, Ivan Sergei"
["description"] => string(212) "An earthquake reaching a 10.5 magnitude on the Richter scale, strikes the west coast of the U.S. and Canada. A large portion of land falls into the ocean, and the situation is worsened by aftershocks and tsunami."
["path"] => string(37) "E:\www\Media\Videos\Disaster\10.5.mp4"
["length"] => string(3) "164"
["size"] => string(4) "3648"
["resolution"] => string(7) "640x272"
["framerate"] => string(5) "29.97"
["videocodec"] => string(3) "AVC"
["videobitrate"] => string(4) "2966"
["label"] => string(10) "Roku Media"
["poster"] => string(15) "images/10.5.jpg"
}
내가 (순간) 생산하기 위해 노력하고있어 각각에 대해 단일 레벨 연관 배열이다 영화. 필자가 읽었고 따라 한 모든 예제는 배열 배열을 생성했습니다. 배열 배열은 작업하기가 훨씬 어렵습니다. 이었나
이되고 난에있어 : 나는 간단하고 분명 뭔가 빠진 것 같은
$iter = new SimpleXMLIterator($xml, 0, TRUE);
Zend_Debug::dump($iter);
//so far xpath has not worked for me, I can't get $result to return anything
$result = $iter->xpath('/xml/viddb/movies/movie');
$movies = array();
for ($iter->rewind(); $iter->valid(); $iter->next()) {
foreach ($iter->getChildren() as $key => $value) {
//I can get each movie title to echo but when I try to put them into an
// array it only has the last record
echo $value->title . '<br />';
$movies['title'] = $value->title;
}
}
return $movies;
내가 느끼는 ... 평소처럼 :) 내 오류를 발견 [편집] , 내가 트립되었다 object의 배열에 대해서. 원하는 방식으로 작동하도록 문자열로 원하는 데이터를 캐스팅해야했습니다. 그냥 여기에 정보를 원하시면 내가 원하는 궤도에 나를 넣어하는 해낸 것입니다 :
public function indexAction() {
$xml = APPLICATION_PATH . '/../data/Videos.xml';
$iter = new SimpleXMLElement($xml, 0, TRUE);
$result = $iter->xpath('//movie');
$movies = array();
foreach ($result as $key => $movie) {
$movies[$key + 1] = (string) $movie->title;
}
Zend_Debug::dump($movies, 'Movies');
}
당신은'$ movies [ 'title'] [] = $ value-> title; – maialithar