Autor Zpráva
juraj
Profil
Zdravím
ako vypíšem hodnotu availability a size_id z parameru size, kde php kód mi vypíše všetky hlavné údaje
<?php     
     $url="";
class ProductsParser {
    var $product;
    var $product_elem;
 // invoked every time open tag is encountered in the stream
// $tag contains the name of the tag and $attributes is a key-value array of tag attributes
function startElement($parser, $tag, $attributes) {
 switch($tag) {
  case 'product':
                $this->product=array('product_id'=>$attributes['product_id'], 
                'text1'=>$attributes['text1'],'text2'=>$attributes['text2'],'text3'=>$attributes['text3'],
                'detail'=>$attributes['detail'],  'meritko'=>$attributes['meritko'],'stav_skladu'=>$attributes['stav_skladu'],
'kategorie'=>$attributes['kategorie'],'link'=>$attributes['link'],'size_id'=>$attributes['size_id'],'availability'=>$attributes['availability'],
 'sizes'=>$attributes['sizes'],   'size'=>$attributes['size'],    'type'=>$attributes['type'], 
                 'price_skk'=>$attributes['price_skk'], 'price_czk'=>$attributes['price_czk'], 'price_pln'=>$attributes['price_pln']
                 
                 )
                 
                 ;
                break;
            case 'text1':
           case 'text2':
           case 'text3':
           case 'meritko':
         case ' stav_skladu':   
        case 'kategorie':                      
        case 'link':    
 case 'size': 
   case 'sizes':
                          case 'variants':       
                              case 'type':        
                              case 'price_skk':
              case 'price_czk':
           case 'price_pln':
                if ($this->product) {
                    $this->product_elem = $tag;
                }
                break;
        }
    }
   
    // invoked on each closing tag
    function endElement($parser, $tag) {
        switch($tag) {
            case 'product':
                if ($this->product) {
                    $this->handle_product();
                    $this->product = null;
                }
                break;
            case 'product_id':
            case 'text1':
           case 'text2':
          case 'text3':
         case 'detail':
                  case 'meritko':
                    case ' stav_skladu':
case 'kategorie': 
                          case 'link':
                          case 'sizes': 
                           case 'size':   
                                    
      case 'variants':         
      case 'type':                          
            case 'price_skk':
            case 'price_czk':
           case 'price_pln':

            
                $this->product_elem = null;
                break;
        }
    }
   
    // invoked each time cdata text is processed
    // note that this may be just a fragment of cdata element so
    // consider that single cdata element can be processed
    // with multiple invocations of this method
    function cdata($parser, $cdata) {
        if ($this->product && $this->product_elem) {
            $this->product[$this->product_elem] .= $cdata;
        }
    }
   
    // invoked each time a complete product is decoded from the stream
    function handle_product() {
        $this->print_product();
    }

    // prints decoded product
    function print_product() {
      /*  echo "\n" . $this->product['product_id'] . ": " . $this->product['text1'] .
        ": " .$this->product['text2']. 
            " (" . $this->product['price_skk'] . ")";       */

         echo   $product_id= $this->product['product_id'];
         echo "&nbsp";
           echo  $text1=  $this->product['text1'];         echo "&nbsp";
          echo     $text2=  $this->product['text2'];     echo "&nbsp";
                    echo     $text3=  $this->product['text3'];     echo "&nbsp";
                        echo     $detail=  $this->product['detail'];     echo "&nbsp";         
                                                echo     $meritko=  $this->product['meritko'];     echo "&nbsp";    
        echo     $stav_skladu=  $this->product['stav_skladu'];     echo "&nbsp"; 
            echo     $kategorie=  $this->product['kategorie'];     echo "&nbsp";   
                        echo     $link=  $this->product['link'];     echo "&nbsp"; 
                            echo     $size_id=  $this->product['size_id'];     echo "&nbsp";
                    
                        echo "<br>";
   echo     $sizes=  $this->product['sizes'];    
    echo     $size=  $this->product['size'];
     echo "<br>";  
    echo     $variants=  $this->product['variants'];     echo "&nbsp";
        echo     $type=  $this->product['type'];     echo "&nbsp";
                    echo     $price_skk=  $this->product['price_skk'];
                    echo "<br>";
                             echo     $price_czk=  $this->product['price_czk'];echo "<br>";
                                                 echo     $price_pln=  $this->product['price_pln'];           
          echo "&nbsp";
                 echo "<br>";                 echo "<br>";
    }
   
}
$xml_handler = new ProductsParser();
$parser = xml_parser_create();
xml_set_object($parser, $xml_handler);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "cdata");

$fp = fopen('https://dedra.blob.core.windows.net/cms/xmlexport/cs_xml_export.xml?ppk=285765', 'r');
while ($data = fread($fp, 4096)) {
    xml_parse($parser, $data, feof($fp));
    flush();
     
}
fclose($fp);
?>
xml súbor
<products>
<product product_id="DA41031" >
<product_id>DA41031</product_id>
<text1>Dámský pásek</text1>
<text2>z ekokůže,modrý</text2>
<text3>šířka: 4 cm</text3>
<detail>Celková délka včetně přezky 125 cm, šířka: 4 cm. materiál: ekokůže</detail>
<meritko></meritko>
<picture1></picture1>
<picture2></picture2>
<picture3></picture3>
<picture4></picture4>
<picture5></picture5>
<picture6></picture6>
<price_czk>199.00</price_czk>
<price_skk>7.99</price_skk>
<price_pln>29.90</price_pln>
<stav_skladu>poslední kusy</stav_skladu>
<kategorie>Móda / Módní doplňky / Pro ženy / Opasky</kategorie>
<variant_text></variant_text>
<variant_image></variant_image>
<sizes>
<size size_id="DA41031" availability="poslední kusy">délka 115 cm</size>
<size size_id="DA41032" availability="IHNED K ODBĚRU">délka 125 cm</size>
</sizes><variants><variant product_id="DA41041" type="Color"/>
<variant product_id="DA41021" type="Color"/></variants>
</product>
</products>

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: