first commit
This commit is contained in:
77
aruba.rzeszow.pl/xml-convert.php
Normal file
77
aruba.rzeszow.pl/xml-convert.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
$file = file_get_contents('https://sklep868139.shoparena.pl/console/integration/execute/name/GoogleProductSearch/lang/pl_PL');
|
||||
$xml = new SimpleXMLElement($file);
|
||||
|
||||
$gid = 'g:id';
|
||||
|
||||
for ( $i = count( $xml -> entry ) - 1; $i >= 0; $i-- )
|
||||
{
|
||||
$id = $xml -> entry[$i] -> children( 'g', true ) -> id;
|
||||
$ids_to_remove = array( 1891, 6272, 6273, 6274, 6275 );
|
||||
|
||||
if ( in_array ($id, $ids_to_remove ) )
|
||||
{
|
||||
// usuń element $xml->entry[$i]
|
||||
unset( $xml -> entry[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
$xml->asXml('feed-main.xml');
|
||||
echo '<p>wygenerowano https://cdn.projectpro.pl/aruba.rzeszow.pl/feed-main.xml</p>';
|
||||
|
||||
// Wczytaj plik XML
|
||||
$xmlString = file_get_contents('https://sklep868139.shoparena.pl/console/integration/execute/name/GoogleProductSearch/lang/pl_PL');
|
||||
$xml = new SimpleXMLElement( $xmlString );
|
||||
|
||||
// Nazwy elementów do usunięcia
|
||||
$elementsToRemove = [
|
||||
'description',
|
||||
'g:condition',
|
||||
'g:availability',
|
||||
'g:price',
|
||||
'g:sale_price',
|
||||
'g:sale_price_effective_date',
|
||||
'g:shipping_weight',
|
||||
'g:shipping',
|
||||
];
|
||||
|
||||
// Namespace dla elementów 'g'
|
||||
$namespaces = $xml->getNamespaces(true);
|
||||
$gNamespace = $namespaces['g'];
|
||||
|
||||
// Pobierz wszystkie elementy entry
|
||||
foreach ($xml->entry as $entry)
|
||||
{
|
||||
foreach ($elementsToRemove as $elementName)
|
||||
{
|
||||
$elementParts = explode(':', $elementName);
|
||||
if (count($elementParts) == 2)
|
||||
{
|
||||
$prefix = $elementParts[0];
|
||||
$localName = $elementParts[1];
|
||||
$elements = $entry->children($namespaces[$prefix])->$localName;
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
// Usuń element z przestrzenią nazw
|
||||
$domElement = dom_import_simplexml($element);
|
||||
$domElement->parentNode->removeChild($domElement);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Usuń element bez przestrzeni nazw
|
||||
$elements = $entry->$elementName;
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$domElement = dom_import_simplexml($element);
|
||||
$domElement->parentNode->removeChild($domElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Zapisz zmodyfikowany XML do nowego pliku
|
||||
$xml->asXML( 'feed-zaufane.xml' );
|
||||
echo '<p>wygenerowano https://cdn.projectpro.pl/aruba.rzeszow.pl/feed-zaufane.xml</p>';
|
||||
?>
|
||||
Reference in New Issue
Block a user