Fehler beim XML Import

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Fehler beim XML Import

    Hallo liebes Team,

    ich versuche eine XML Datei in eine Datenbank zu überführen, dabei triff folgendes Phenomän auf, es werden Filme, Schauspieler u.s.w. in die Datenbank übergeben, wenn ein Film nur einen Schauspieler hat, dann wird nur der erste Buchstabe in die Tabelle übernommen und die actorID ist auch falsch.

    Das Resultat des Import sieht so aus:

    Import wird durchgeführt...

    Array ( [0] => Tasha Hunter [1] => Ryan [2] => Alana Evans [3] => Chris Mountain [4] => Elizabeth Lawrence [5] => Ana nova ) Array ( [0] => Tristan [1] => Melissa Milano [2] => Lena Juliette [3] => Paola Rey [4] => Jasmine Byrne [5] => Neveah [6] => Jackie Diaz [7] => Vanessa Figueroa [8] => Paige Taylor [9] => Alexis Love ) Array ( [0] => Peaches [1] => Shorty [2] => Reggie [3] => G-Man [4] => Foxey [5] => Pretty Tony ) Array ( [0] => Ginger Lynn [1] => Viper [2] => Billy Dee [3] => Sharon Mitchell [4] => Marc Wallace [5] => Jerry Butler [6] => Kristara Barrington [7] => Rick Savage [8] => Harry Reems [9] => Greg Rome [10] => Dan T. Mann [11] => Sandy Taylor [12] => Crystal Loving [13] => Danica Rae [14] => Debbie Does [15] => Don Osmand ) Array ( [0] => Tony Cappuci [1] => Jake Cruise ) Array ( [0] => Mark Wood [1] => Lee Bang [2] => Alex Gonz [3] => Kitty Wildwood [4] => Britney Blew [5] => Mimi Allen [6] => C-Lo [7] => Nikki Vee [8] => Jessie Electra ) Array ( [0] => Bunny Bleu [1] => Taija Rae [2] => Honey Wilder [3] => Janey Robbins ) Array ( [0] => Brooke [1] => Alexis May [2] => Keiran Lee [3] => Alysha Tyler [4] => Jez Christ [5] => Simon Girth ) Array ( [0] => Amile Waters [1] => Ms. Platinum [2] => Jordan Skye [3] => Gorgeouz ) Array ( [0] => Tristan [1] => Lindsey Meadows [2] => Kacey Villainess [3] => lielani [4] => Jocelyn Jayden [5] => Priscilla Milan [6] => Italia Christie [7] => Joey Ray [8] => Barry Scott [9] => Derrick Pierce [10] => Johnny Sins [11] => Big Pike ) Array ( [0] => Max Hardcore [1] => Vivian [2] => Candi Cash ) Array ( [0] => Eva [1] => Lucky [2] => Iveta [3] => Erik [4] => Mirek [5] => Jerry Harris [6] => Rado [7] => Hans Strong [8] => Carlo Horky [9] => Idka [10] => Alexa Bold ) Array ( [0] => Nyomi Marcela [1] => Sandra Romain [2] => Harmony [3] => Faith Leon [4] => Cassandra Cruz [5] => Misty Stone [6] => Bree Olson [7] => Erika Vution [8] => Lauren Vaughn ) Array ( [0] => Chayse Evans [1] => Kalee Hunter [2] => Tera Dice [3] => Tara Bentley [4] => Alyssa Hall ) Array ( [0] => Sean Michaels [1] => Lili Marlene [2] => Summer Rose [3] => Paul Thomas [4] => Carol Cummings [5] => Saki [6] => Sabrina Dawn [7] => Dan Mann ) Array ( [0] => Mistress D [1] => Jimmy Broadway ) Array ( [0] => Jill Kelly [1] => Vince Vouyer ) Array ( [0] => Lena [1] => Klava [2] => Jerry Geroshvile [3] => Nina Saley [4] => Ulia Butina [5] => Kalina Sharina [6] => Tonova Taisia ) Array ( [0] => Rene Morgan [1] => Whitney Prescott [2] => Doreen Lazlo ) Array ( [0] => Kalena Rios (TVTS) [1] => Cinthya Maia [2] => Priscila Ferrari [3] => Anytha Cordeiro [4] => Fernanda Alencar ) Array ( [0] => Mistress Jade Indica [1] => Slave Liam [2] => Liam [3] => Jade Indica ) Array ( [0] => Julian [1] => Kandi Peach ) NaomiArray ( [0] => Cindy [1] => Allison Wyte [2] => Rick Masters [3] => Layla Rivera [4] => Summer Luv [5] => Honey B [6] => Katio Kailin ) Array ( [0] => Lynden Johnson [1] => Jaye Milo [2] => Brittany O\'Neil [3] => Angel Bust [4] => Randy Spears [5] => Tom Byron [6] => Mike Horner ) Array ( [0] => Mia Smiles [1] => Mika Tan [2] => Jasmine [3] => Lyla Lei [4] => May [5] => Naomi [6] => Saphire [7] => Dana Vespoli [8] => Tami Lynn [9] => Connie [10] => Carman Sancha [11] => Ayoko [12] => Kyanna Lee [13] => Niya Yu [14] => Luci Thai ) . . .

    An der Stelle, die ich Fett markiert habe tritt der Fehler auf, wie man sieht ist auch kein array erzeugt worden. Zum Import benutze ich folgende Scripts:

    Quellcode

    1. <p> Import wird durchgeführt...<p>
    2. <?php
    3. sleep(1);
    4. ?>
    5. <?php
    6. ini_set("max_execution_time","false");
    7. include 'import1.php';
    8. ?>
    Alles anzeigen


    Quellcode

    1. <?php
    2. set_time_limit(0);
    3. require_once 'simplexml.class.php';
    4. $file = 'http://www.roter-planet.de/import.xml';
    5. $sxml = new simplexml;
    6. $data = $sxml->xml_load_file($file,"array");
    7. include 'dbconnect.php';
    8. $find[] = "<b>";
    9. $replace[] = "ß";
    10. $data = str_replace($find, $replace, $data);
    11. $find[] = "</b>";
    12. $replace[] = "ß";
    13. $data = str_replace($find, $replace, $data);
    14. foreach ($data["dvds"]["dvd"] as $dvd)
    15. {
    16. $videoID = (int)trim($dvd["videoID"]);
    17. $title = trim($dvd["title"]);
    18. $description = trim($dvd["description"]);
    19. $weight = (int)trim($dvd["weight"]);
    20. $studioTitle = trim($dvd["studioTitle"]);
    21. $releaseDate = $dvd["releaseDate"];
    22. $find[550] = " ";
    23. $replace[550] = "-";
    24. $releaseDate = str_replace($find, $replace, $releaseDate);
    25. $find[550] = ":";
    26. $replace[550] = "-";
    27. $releaseDate = str_replace($find, $replace, $releaseDate);
    28. $thumbUncensored = trim($dvd["images"]["thumbUncensored"]);
    29. $coverUncensored = trim($dvd["images"]["coverUncensored"]);
    30. $thumbCensored = trim($dvd["images"]["thumbCensored"]);
    31. $coverCensored = trim($dvd["images"]["coverCensored"]);
    32. $find[] = "%";
    33. $replace[] = " Prozent";
    34. $title = str_replace($find, $replace, $title);
    35. $find[] = "ß";
    36. $replace[] = "ß";
    37. $title = str_replace($find, $replace, $title);
    38. $find[] = "ä";
    39. $replace[] = "ä";
    40. $title = str_replace($find, $replace, $title);
    41. $find[] = "ö";
    42. $replace[] = "ö";
    43. $title = str_replace($find, $replace, $title);
    44. $find[] = "ü";
    45. $replace[] = "ü";
    46. $title = str_replace($find, $replace, $title);
    47. $find[] = "“";
    48. $replace[] = "\"";
    49. $title = str_replace($find, $replace, $title);
    50. $find[] = "”";
    51. $replace[] = "\"";
    52. $title = str_replace($find, $replace, $title);
    53. $find[] = "'";
    54. $replace[] = "";
    55. $title = str_replace($find, $replace, $title);
    56. $find[] = "'";
    57. $replace[] = "";
    58. $description = str_replace($find, $replace, $description);
    59. $find[] = "\'";
    60. $replace[] = "";
    61. $description = str_replace($find, $replace, $description);
    62. $find[] = "\\";
    63. $replace[] = "";
    64. $description = str_replace($find, $replace, $description);
    65. $find[] = "'";
    66. $replace[] = "";
    67. $studioTitle = str_replace($find, $replace, $studioTitle);
    68. $sql = "REPLACE INTO movies (title, videoID, description, studioTitle, releaseDate, thumbUncensored, coverUncensored, thumbCensored, coverCensored) VALUES ('$title', $videoID, '$description', '$studioTitle', '$releaseDate', '$thumbUncensored', '$coverUncensored', '$thumbCensored', '$coverCensored')";
    69. mysql_query($sql) or die(mysql_error());
    70. $newMovieID = mysql_insert_id();
    71. $actorNames = $dvd["actorInformation"]["actorNames"]["actorName"];
    72. $actorIDs = $dvd["actorInformation"]["actorIDs"]["actorID"];
    73. $catNames = $dvd["categoryInformation"]["mainCategoriesGerman"]["mainCategoryGerman"];
    74. $subcatNames = $dvd["categoryInformation"]["subCategoriesGerman"]["subCategoryGerman"];
    75. print_r($actorNames);
    76. for ($i = 0, $c = count($actorNames); $i < $c; $i++)
    77. {
    78. $name = $actorNames[$i];
    79. $externalID = (int)trim($actorIDs[$i]);
    80. $sql = "REPLACE INTO actors (name, actorID, videoID) VALUES ('$name', '$externalID', '$videoID')";
    81. mysql_query($sql) or die(mysql_error());
    82. $newActorID = mysql_insert_id();
    83. $sql = "REPLACE INTO actorsmovies (actorID, movieID) VALUES ('$newActorID','$newMovieID')";
    84. mysql_query($sql) or die(mysql_error());
    85. }
    86. for ($i = 0, $c = count($catNames); $i < $c; $i++)
    87. {
    88. $cat = $catNames[$i];
    89. $sql = "INSERT INTO cat (catName, videoID) VALUES ('$cat', $videoID)";
    90. mysql_query($sql) or die(mysql_error());
    91. //print_r($sql);
    92. $newsubcatID = mysql_insert_id();
    93. $sql = "INSERT INTO catmovies (catID, movieID, videoID) VALUES ($newsubcatID,$newMovieID,$videoID)";
    94. //print_r($sql);
    95. mysql_query($sql) or die(mysql_error());
    96. }
    97. for ($i = 0, $c = count($subcatNames); $i < $c; $i++)
    98. {
    99. $subcat = trim($subcatNames[$i]);
    100. $sql = "INSERT INTO subcat (subcatName, videoID) VALUES ('$subcat', $videoID)";
    101. mysql_query($sql) or die(mysql_error());
    102. $newcatID = mysql_insert_id();
    103. $sql = "INSERT INTO subcatmovies (subcatID, movieID, videoID) VALUES ($newcatID,$newMovieID,$videoID)";
    104. //print_r($sql);
    105. mysql_query($sql) or die(mysql_error());
    106. }
    107. }
    108. echo "IMPORT 1 ERFOLGREICH!<br>";
    109. mysql_close();
    110. ?>
    111. <style type="text/css">
    112. .txt{
    113. font-family:Arial, Helvetica, sans-serif;
    114. font-size:12px;
    115. }
    116. #box{
    117. width:700px;
    118. border:1px solid #000;
    119. padding:10px;
    120. }
    121. </style>
    Alles anzeigen


    . . .fortsetzung im nächsten Post
    Man muss nicht wissen wie es geht, man muss nur wissen wo es steht! Natürlich bei easy-coding 8o de

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von kingluui ()

  • und folgende Klasse:

    Quellcode

    1. <?php
    2. /**
    3. * If the result will be an object, this container class is used.
    4. *
    5. */
    6. class SimpleXMLObject{
    7. function attributes(){
    8. $container = get_object_vars($this);
    9. return (object) $container["@attributes"];
    10. }
    11. function content(){
    12. $container = get_object_vars($this);
    13. return (object) $container["@content"];
    14. }
    15. }
    16. /**
    17. * The Main XML Parser Class
    18. *
    19. */
    20. class simplexml {
    21. var $result = array();
    22. var $ignore_level = 0;
    23. var $skip_empty_values = false;
    24. var $php_errormsg;
    25. var $evalCode="";
    26. /**
    27. * Adds Items to Array
    28. *
    29. * @param int $level
    30. * @param array $tags
    31. * @param $value
    32. * @param string $type
    33. */
    34. function array_insert($level, $tags, $value, $type)
    35. {
    36. $temp = '';
    37. for ($c = $this->ignore_level + 1; $c < $level + 1; $c++) {
    38. if (isset($tags[$c]) && (is_numeric(trim($tags[$c])) || trim($tags[$c]))) {
    39. if (is_numeric($tags[$c])) {
    40. $temp .= '[' . $tags[$c] . ']';
    41. } else {
    42. $temp .= '["' . $tags[$c] . '"]';
    43. }
    44. }
    45. }
    46. $this->evalCode .= '$this->result' . $temp . "=\"" . addslashes($value) . "\";//(" . $type . ")\n";
    47. #echo $code. "\n";
    48. }
    49. /**
    50. * Define the repeated tags in XML file so we can set an index
    51. *
    52. * @param array $array
    53. * @return array
    54. */
    55. function xml_tags($array)
    56. { $repeats_temp = array();
    57. $repeats_count = array();
    58. $repeats = array();
    59. if (is_array($array)) {
    60. $n = count($array) - 1;
    61. for ($i = 0; $i < $n; $i++) {
    62. $idn = $array[$i]['tag'].$array[$i]['level'];
    63. if(in_array($idn,$repeats_temp)){
    64. $repeats_count[array_search($idn,$repeats_temp)]+=1;
    65. }else{
    66. array_push($repeats_temp,$idn);
    67. $repeats_count[array_search($idn,$repeats_temp)]=1;
    68. }
    69. }
    70. }
    71. $n = count($repeats_count);
    72. for($i=0;$i<$n;$i++){
    73. if($repeats_count[$i]>1){
    74. array_push($repeats,$repeats_temp[$i]);
    75. }
    76. }
    77. unset($repeats_temp);
    78. unset($repeats_count);
    79. return array_unique($repeats);
    80. }
    81. /**
    82. * Converts Array Variable to Object Variable
    83. *
    84. * @param array $arg_array
    85. * @return $tmp
    86. */
    87. function array2object ($arg_array)
    88. {
    89. if (is_array($arg_array)) {
    90. $keys = array_keys($arg_array);
    91. if(!is_numeric($keys[0])) $tmp = new SimpleXMLObject;
    92. foreach ($keys as $key) {
    93. if (is_numeric($key)) $has_number = true;
    94. if (is_string($key)) $has_string = true;
    95. }
    96. if (isset($has_number) and !isset($has_string)) {
    97. foreach ($arg_array as $key => $value) {
    98. $tmp[] = $this->array2object($value);
    99. }
    100. } elseif (isset($has_string)) {
    101. foreach ($arg_array as $key => $value) {
    102. if (is_string($key))
    103. $tmp->$key = $this->array2object($value);
    104. }
    105. }
    106. } elseif (is_object($arg_array)) {
    107. foreach ($arg_array as $key => $value) {
    108. if (is_array($value) or is_object($value))
    109. $tmp->$key = $this->array2object($value);
    110. else
    111. $tmp->$key = $value;
    112. }
    113. } else {
    114. $tmp = $arg_array;
    115. }
    116. return $tmp; //return the object
    117. }
    118. /**
    119. * Reindexes the whole array with ascending numbers
    120. *
    121. * @param array $array
    122. * @return array
    123. */
    124. function array_reindex($array)
    125. {
    126. if (is_array($array)) {
    127. if(count($array) == 1 && $array[0]){
    128. return $this->array_reindex($array[0]);
    129. }else{
    130. foreach($array as $keys => $items) {
    131. if (is_array($items)) {
    132. if (is_numeric($keys)) {
    133. $array[$keys] = $this->array_reindex($items);
    134. } else {
    135. $array[$keys] = $this->array_reindex(array_merge(array(), $items));
    136. }
    137. }
    138. }
    139. }
    140. }
    141. return $array;
    142. }
    143. /**
    144. * Parse the XML generation to array object
    145. *
    146. * @param array $array
    147. * @return array
    148. */
    149. function xml_reorganize($array)
    150. {
    151. $count = count($array);
    152. $repeat = $this->xml_tags($array);
    153. $repeatedone = false;
    154. $tags = array();
    155. $k = 0;
    156. for ($i = 0; $i < $count; $i++) {
    157. switch ($array[$i]['type']) {
    158. case 'open':
    159. array_push($tags, $array[$i]['tag']);
    160. if ($i > 0 && ($array[$i]['tag'] == $array[$i-1]['tag']) && ($array[$i-1]['type'] == 'close'))
    161. $k++;
    162. if (isset($array[$i]['value']) && ($array[$i]['value'] || !$this->skip_empty_values)) {
    163. array_push($tags, '@content');
    164. $this->array_insert(count($tags), $tags, $array[$i]['value'], "open");
    165. array_pop($tags);
    166. }
    167. if (in_array($array[$i]['tag'] . $array[$i]['level'], $repeat)) {
    168. if (($repeatedone == $array[$i]['tag'] . $array[$i]['level']) && ($repeatedone)) {
    169. array_push($tags, strval($k++));
    170. } else {
    171. $repeatedone = $array[$i]['tag'] . $array[$i]['level'];
    172. array_push($tags, strval($k));
    173. }
    174. }
    175. if (isset($array[$i]['attributes']) && $array[$i]['attributes'] && $array[$i]['level'] != $this->ignore_level) {
    176. array_push($tags, '@attributes');
    177. foreach ($array[$i]['attributes'] as $attrkey => $attr) {
    178. array_push($tags, $attrkey);
    179. $this->array_insert(count($tags), $tags, $attr, "open");
    180. array_pop($tags);
    181. }
    182. array_pop($tags);
    183. }
    184. break;
    185. case 'close':
    186. array_pop($tags);
    187. if (in_array($array[$i]['tag'] . $array[$i]['level'], $repeat)) {
    188. if ($repeatedone == $array[$i]['tag'] . $array[$i]['level']) {
    189. array_pop($tags);
    190. } else {
    191. $repeatedone = $array[$i + 1]['tag'] . $array[$i + 1]['level'];
    192. array_pop($tags);
    193. }
    194. }
    195. break;
    196. case 'complete':
    197. array_push($tags, $array[$i]['tag']);
    198. if (in_array($array[$i]['tag'] . $array[$i]['level'], $repeat)) {
    199. if ($repeatedone == $array[$i]['tag'] . $array[$i]['level'] && $repeatedone) {
    200. array_push($tags, strval($k));
    201. } else {
    202. $repeatedone = $array[$i]['tag'] . $array[$i]['level'];
    203. array_push($tags, strval($k));
    204. }
    205. }
    206. if (isset($array[$i]['value']) && ($array[$i]['value'] || !$this->skip_empty_values)) {
    207. if (isset($array[$i]['attributes']) && $array[$i]['attributes']) {
    208. array_push($tags, '@content');
    209. $this->array_insert(count($tags), $tags, $array[$i]['value'], "complete");
    210. array_pop($tags);
    211. } else {
    212. $this->array_insert(count($tags), $tags, $array[$i]['value'], "complete");
    213. }
    214. }
    215. if (isset($array[$i]['attributes']) && $array[$i]['attributes']) {
    216. array_push($tags, '@attributes');
    217. foreach ($array[$i]['attributes'] as $attrkey => $attr) {
    218. array_push($tags, $attrkey);
    219. $this->array_insert(count($tags), $tags, $attr, "complete");
    220. array_pop($tags);
    221. }
    222. array_pop($tags);
    223. }
    224. if (in_array($array[$i]['tag'] . $array[$i]['level'], $repeat)) {
    225. array_pop($tags);
    226. $k++;
    227. }
    228. array_pop($tags);
    229. break;
    230. }
    231. }
    232. eval($this->evalCode);
    233. $last = $this->array_reindex($this->result);
    234. return $last;
    235. }
    236. /**
    237. * Get the XML contents and parse like SimpleXML
    238. *
    239. * @param string $file
    240. * @param string $resulttype
    241. * @param string $encoding
    242. * @return array/object
    243. */
    244. function xml_load_file($file, $resulttype = 'object', $encoding = 'ISO-8859-1')
    245. {
    246. $php_errormsg="";
    247. $this->result="";
    248. $this->evalCode="";
    249. $values="";
    250. //$data = file_get_contents($file);
    251. $url = $file;
    252. $ch = curl_init();
    253. curl_setopt($ch, CURLOPT_HEADER, 0);
    254. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    255. curl_setopt($ch, CURLOPT_URL, $url);
    256. $data = curl_exec($ch);
    257. if (!$data)
    258. return 'Cannot open xml document: ' . (isset($php_errormsg) ? $php_errormsg : $file);
    259. $parser = xml_parser_create($encoding);
    260. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    261. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    262. $ok = xml_parse_into_struct($parser, $data, $values);
    263. if (!$ok) {
    264. $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)",
    265. xml_get_error_code($parser),
    266. xml_error_string(xml_get_error_code($parser)),
    267. xml_get_current_line_number($parser),
    268. xml_get_current_column_number($parser),
    269. xml_get_current_byte_index($parser));
    270. }
    271. xml_parser_free($parser);
    272. if (!$ok)
    273. return $errmsg;
    274. if ($resulttype == 'array')
    275. return $this->xml_reorganize($values);
    276. // default $resulttype is 'object'
    277. return $this->array2object($this->xml_reorganize($values));
    278. }
    279. }
    280. ?>
    Alles anzeigen


    warum wird kein ordentliches array() erkannt?

    Kann sich jemand da rein denken, und hat jemand eine Idee?

    LG

    kingluui
    Man muss nicht wissen wie es geht, man muss nur wissen wo es steht! Natürlich bei easy-coding 8o de
  • Hi.
    Installiere dir lieber mal PHP5. 307 Zeilen XML Parser zu Debuggen ist nicht so einfach. Und wer sagt überhaupt, dass das XML Dokument gültig ist.
    Die resultierenden Fehler sind klar, wenn mit Array Funktionen auf einen String zugegriffen wird. (Ein String ist auch nur ein Array von Buchstaben) - aktivier mal error_reporting(E_ALL)