• 15-07-2015, 16:00:45
    #1
    <variants>
    <product>
    <variant>
    <spec name="Renk">LACİVERT</spec>
    <spec name="Beden">40</spec>
    <quantity>0</quantity>
    <price>0.00</price>
    </variant></variants>
    </product>
    $xml_file = simplexml_load_file("");
    $Urunler = $xml_file->xpath('//Product');
    
    foreach($Urunler as $Urun){
    	foreach($Urun->variants as  $variant){
    		$xml_etiket .= "<Numara>";
    		foreach($variant as $spec){
    			$spec = array(
    				"Beden" => $spec->Beden[1],
    			);
    			$xml_etiket .= $spec['Beden'].":0.00:0.00:1:select|";
    		}
    		$xml_etiket .= "</Numara>";
    		$xml_etiket .= "\n";
    		
    	}
    }
    Bu xml yapısından verileri nasıl sağlık bir şekilde çekebilirim tag içinde özellik tanımlanması beynimi karıştırdı

    Fikirlerinizi bekliyorum.
  • 15-07-2015, 17:53:34
    #2
    Almanız gereken çıktının şemasını paylaşırsanız daha hızlı çözüm üretilebilir.
  • 15-07-2015, 18:05:17
    #3
    <spec name="Renk">LACİVERT</spec>
    <spec name="Beden">40</spec>

    bu alanları

    <renk></renk>
    <Numara></Numara>

    olarak almak istiyorum.

    Biraz uğraşınca yapabildim doğruluğunu kontrol ederseniz sevinirim.
    $xml_etiket .= "<Numara>";
    		foreach($Urun->children() as $child) {
    				foreach($child as $key => $value) {
    					$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";
    				}
    		}
    	$xml_etiket .= "</Numara>";
    Ek bir soru
     $xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";
    sondaki ayraçı "|" eklediğimde döngüde hepsinin sonuna geliyor, son verinin sonuna gelmemesi için ne yapabilirim.
  • 15-07-2015, 18:51:32
    #4
    Print_r($Urunler); yapar misin foreach ten once ciktiyi paylasir misin
  • 15-07-2015, 19:39:35
    #5
    Array
    (
        [0] => SimpleXMLElement Object
            (
                [Product_id] => 4
                [Name] => SimpleXMLElement Object
                    (
                    )
    
                [kategori1] => SimpleXMLElement Object
                    (
                    )
    
                [kategori2] => SimpleXMLElement Object
                    (
                    )
    
                [kategori3] => SimpleXMLElement Object
                    (
                    )
    
                [Price] => 120.36
                [CurrencyType] => TRL
                [Tax] => 8
                [Stock] => 3
                [Brand] => SimpleXMLElement Object
                    (
                    )
    
                [Image1] => http://www.xxx.com/image/data/resimler/docker-216307-603.jpg
                [Image2] => http://www.xxx.com/image/data/resimler/docker-216307-604.jpg
                [Description] => SimpleXMLElement Object
                    (
                    )
    
                [variants] => SimpleXMLElement Object
                    (
                        [variant] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 40
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [1] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 41
                                            )
    
                                        [quantity] => 2
                                        [price] => 0.00
                                    )
    
                                [2] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 42
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [3] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 43
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [4] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 44
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [5] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 45
                                            )
    
                                        [quantity] => 1
                                        [price] => 0.00
                                    )
    
                            )
    
                    )
    
            )
    
        [1] => SimpleXMLElement Object
            (
                [Product_id] => 5
                [Name] => SimpleXMLElement Object
                    (
                    )
    
                [kategori1] => SimpleXMLElement Object
                    (
                    )
    
                [kategori2] => SimpleXMLElement Object
                    (
                    )
    
                [kategori3] => SimpleXMLElement Object
                    (
                    )
    
                [Price] => 74.06
                [CurrencyType] => TRL
                [Tax] => 8
                [Stock] => 4
                [Brand] => SimpleXMLElement Object
                    (
                    )
    
                [Image1] => http://www.xxx.com/image/data/resimler/docker-216607-492.jpg
                [Image2] => http://www.xxx.com/image/data/resimler/docker-216607-493.jpg
                [Description] => SimpleXMLElement Object
                    (
                    )
    
                [variants] => SimpleXMLElement Object
                    (
                        [variant] => Array
                            (
                                [0] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => KUM
                                                [1] => 36
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [1] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => KUM
                                                [1] => 37
                                            )
    
                                        [quantity] => 1
                                        [price] => 0.00
                                    )
    
                                [2] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => KUM
                                                [1] => 38
                                            )
    
                                        [quantity] => 1
                                        [price] => 0.00
                                    )
    
                                [3] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => KUM
                                                [1] => 39
                                            )
    
                                        [quantity] => 1
                                        [price] => 0.00
                                    )
    
                                [4] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => KUM
                                                [1] => 40
                                            )
    
                                        [quantity] => 1
                                        [price] => 0.00
                                    )
    
                                [5] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 36
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [6] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 37
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [7] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 38
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [8] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 39
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                                [9] => SimpleXMLElement Object
                                    (
                                        [spec] => Array
                                            (
                                                [0] => LACİVERT
                                                [1] => 40
                                            )
    
                                        [quantity] => 0
                                        [price] => 0.00
                                    )
    
                            )
    
                    )
    
            )


    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 19:39:35 -->-> Daha önceki mesaj 18:56:45 --

    $xml_etiket = preg_replace("/\|<\/Numara>/", "</Numara>", $xml_etiket);
    Bu olayıda bu şekilde çözdüm sonradan hatırladım sizide meşgul ettim kusura bakmayın
  • 15-07-2015, 19:44:23
    #6
    MoreMor adlı üyeden alıntı: mesajı görüntüle
    <spec name="Renk">LACİVERT</spec>
    <spec name="Beden">40</spec>

    bu alanları

    <renk></renk>
    <Numara></Numara>

    olarak almak istiyorum.

    Biraz uğraşınca yapabildim doğruluğunu kontrol ederseniz sevinirim.
    $xml_etiket .= "<Numara>";
    		foreach($Urun->children() as $child) {
    				foreach($child as $key => $value) {
    					$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";
    				}
    		}
    	$xml_etiket .= "</Numara>";
    Ek bir soru
     $xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";
    sondaki ayraçı "|" eklediğimde döngüde hepsinin sonuna geliyor, son verinin sonuna gelmemesi için ne yapabilirim.
    http://stackoverflow.com/a/1070256 son adıma | işaret koydurmamak istiyorsan bunu bir incele
    if($i != $len-1){$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";}
    else{$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1";}
    gibi yapabilirsin. mobil olduğum için daha fazla yardımcı olamadım kusura bakmayın.
  • 15-07-2015, 19:47:58
    #7
    ufukt51 adlı üyeden alıntı: mesajı görüntüle
    http://stackoverflow.com/a/1070256 son adıma | işaret koydurmamak istiyorsan bunu bir incele
    if($i != $len-1){$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1|";}
    else{$xml_etiket .=  $value->spec[1].":".$value->quantity.":1:0.00:0:1";}
    gibi yapabilirsin. mobil olduğum için daha fazla yardımcı olamadım kusura bakmayın.
    Teşekkürler ufuk preg_replace ile daha ufak bir kodla çözdüm yardımlaşma duyguna minnettarım.