Untitled
plain_text
20 days ago
2.6 kB
1
Indexable
Never
<?php // XML verisini çek $xml_url = 'https://cdn1.xmlbankasi.com/p1/gumush/image/data/xml/gumush.xml'; $xml_content = file_get_contents($xml_url); // SimpleXML ile veriyi ayrıştır $xml = simplexml_load_string($xml_content); // Yeni bir XML oluştur // Yeni bir XML oluştur $new_xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><Products></Products>'); // Verileri döngü ile işle ve yeni XML'e ekle foreach ($xml->Product as $product) { $new_product = $new_xml->addChild('Product'); $new_product->addChild('urunler', $product->urunler); $new_product->addChild('Product_id', $product->Product_id); $new_product->addChild('Name', $product->Name); // mainCategory, category ve subCategory verilerini XML uyumlu hale getirerek categoryPath oluşturun $mainCategory = htmlspecialchars((string)$product->mainCategory, ENT_XML1, 'UTF-8'); $category = htmlspecialchars((string)$product->category, ENT_XML1, 'UTF-8'); $subCategory = htmlspecialchars((string)$product->subCategory, ENT_XML1, 'UTF-8'); $categoryPath = $mainCategory . ' > ' . $category; if (!empty($subCategory)) { $categoryPath .= ' > ' . $subCategory; } $new_product->addChild('categoryPath', $categoryPath); $new_product->addChild('Price', $product->Price); $new_product->addChild('Price2', $product->Price2); $new_product->addChild('CurrencyType', $product->CurrencyType); $new_product->addChild('Tax', $product->Tax); $new_product->addChild('Stock', $product->Stock); $new_product->addChild('Brand', $product->Brand); $new_product->addChild('Image1', $product->Image1); $new_product->addChild('Image2', $product->Image2); $new_product->addChild('Image3', $product->Image3); $new_product->addChild('Image4', $product->Image4); $new_product->addChild('Image5', $product->Image5); // category öğesini düzenle // $new_product->category = htmlspecialchars($new_product->category, ENT_XML1); // Description öğesini düzenle // $new_product->Description = htmlspecialchars($new_product->Description, ENT_XML1); // Description içeriğini eklerken CDATA kullanarak HTML kodlarını koru $description = $new_product->addChild('Description'); $description->addChild('![CDATA[' . $product->Description . ']]'); // $new_product->addChild('Description', $new_product->Description); } // XML dosyasını kaydet $new_xml->asXML('yeni_veri.xml'); // Yeni XML'i ekrana bastırmak için header('Content-Type: text/xml'); echo $new_xml->asXML(); ?>