%)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
private function parsePriceXml(){
$rules = $this->parse_rules;
if(!isset($rules['main_element_name']) || !is_array($rules['columns']) || empty($rules['columns'])){
throw new Bad_Rules_Array_Exception();
}
$xml = simplexml_load_file($this->filename);
if(!$xml) throw new File_Loading_Problems_Exception();
$count = 1;
$data = array();
foreach($xml->$rules['main_element_name'] as $node){
foreach ($rules['columns'] as $k=>$v){
if($v == false) {
$data[$count][$k] = '';
continue;
}
if(!is_array($v)){
$el_names = explode('+',$v);
if(count($el_names)>1){
$el_values = array();
foreach($el_names as $val){
$result = $xml->xpath($rules['main_element_name'].'['.$count.']//'.$val.'[1]');
if(!empty($result)) $el_values[] = (string)self::convertEncoding($result[0], 'UTF-8', $this->output_encoding);
}
$data[$count][$k] = implode(' ',$el_values);
}else{
$result = $xml->xpath($rules['main_element_name'].'['.$count.']//'.$v.'[1]');
if(!empty($result)){
$data[$count][$k] = (string)self::convertEncoding($result[0], 'UTF-8', $this->output_encoding);
}else{
$data[$count][$k] = '';
}
}
}else{
foreach($v as $value){
$el_names = explode('+',$value);
if(count($el_names)>1){
$el_values = array();
foreach($el_names as $val){
$result = $xml->xpath($rules['main_element_name'].'['.$count.']//'.$val.'[1]');
if(!empty($result)) $el_values[] = (string)self::convertEncoding($result[0], 'UTF-8', $this->output_encoding);
}
if(empty($el_values))continue;
$data[$count][$k] = implode(' ',$el_values);
break;
}else{
$result = $xml->xpath($rules['main_element_name'].'['.$count.']//'.$value.'[1]');
if(!empty($result)){
$data[$count][$k] = (string)self::convertEncoding($result[0], 'UTF-8', $this->output_encoding);
break;
}else{
continue;
}
}
}
}
}
$count++;
}
$this->data = $data;
$this->cleanData();
}