XML naar databse mogelijkheden

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Bryan De Baar

Bryan De Baar

01/10/2018 13:11:21
Quote Anchor link
Hallo,


Is er een mogelijkheid om van XML bestanden die je hebt over te zetten naar een SQL database?
Wat is er aan de hand:

Momenteel maken wij gebruik van een software pakket voor onze webshop, deze site maakt geen gebruik van een SQL database maar enkel met XML bestanden waarin de prijs, de link naar de afbeeldingen en andere informatie betreft de artikelen.
Via php word dan dit bestand geopend en word de informatie uitgelezen en daarna gepresenteerd.

Helaas word dit software pakket niet meer ondersteund en zullen wij dus over moeten stappen naar iets anders.
Nu willen ik met Magento gaan werken en moeten dus alle artikelen worden overgezet.

Als je ongeveer 13.000 artikelen hebt is dit niet te doen om alles opnieuw in te voeren, daarom zoek ik naar een mogelijkheid om van XML te switchen naar een SQL database.


Data overzetten vanuit 2 verschillende systemen heb ik geen ervaring, vandaar dat ik om hulp vraag wat mogelijk is.


Groetjes Bryan
 
PHP hulp

PHP hulp

20/04/2024 11:05:17
 
- Ariën  -
Beheerder

- Ariën -

01/10/2018 13:17:04
Quote Anchor link
Opsich is dit eenvoudig te doen met SimpleXML in PHP, en alle informatie uitlezen in een loop en INSERT'en in de database.

Mogelijk dat je hier een daar een kleine conversie moet draaien voor de datum en of de tijd.
Gewijzigd op 01/10/2018 13:17:58 door - Ariën -
 
Thomas van den Heuvel

Thomas van den Heuvel

01/10/2018 14:39:06
Quote Anchor link
De vraag is ook of de structuur van de data in de XML-bestanden zich leent om 1:1 overgezet te worden in een database.

En dan is er vanuit een systeem/pakket (Magento) misschien ook een voorgeschreven vorm waarin dit zou moeten passen.

Grote kans dat je naast het importeren ook nog het een en ander zult moeten converteren/(her)structureren.

En dan is er misschien ook nog de uiteindelijke vorm waarin je de data wilt gaan gebruiken, die dicteert mede hoe dit gestructureerd zou moeten zijn. Het houdt niet op bij het vinden van een manier om iets een database in te krijgen, daarna moet je het er ook weer op een fatsoenlijke manier uit kunnen halen die (zo) makkelijk (mogelijk) is in het gebruik.
 
Ivo P

Ivo P

01/10/2018 14:44:13
Quote Anchor link
ik denk dat je de data niet rechtstreeks in de database moet willen zetten.

Magento is daar te complex voor. Maar Magento bevat mogelijkheden om data te importeren via excelsheets.

Ik zou gaan voor die mogelijkheid en zou de xml vertalen naar een excelsheet met de juiste opbouw.
Als dat compleet is, kun je die sheets vervolgens importeren.

Dat voorkomt, dat je mogelijk ergens een vlaggetje vergeet in een tabel, of straks 13000 prijzen hebt, maar 0 bijbehorende producten omdat die geen leverancier hadden of iets dergelijks. En je wilt niet je database vervuilen met kapotte data.
 
Bryan De Baar

Bryan De Baar

01/10/2018 22:47:48
Quote Anchor link
Dank voor de reacties.

Ik zie dat Magento inderdaad excel maar ook XML bestanden importeert, nu wil ik de bestande XML omzetten naar de Magento XML en daarvoor wil ik gebruik maken van de loop functie. Om te kijken welke waarde ik nodig heb en of de juiste informatie uit de XML word gehaald heb ik een preview pagina gemaakt.

Eerst heb ik een test gedaan met de GET global welke werkte, maar de loop zoals ik die nu heb werkt op een of andere manier niet.


Get global
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
if(isset($_GET['sku'])) {
    $file = dirname(__FILE__).'/articles/'.$_GET['sku'].'.xml';
    if(file_exists($file)) {
        $article = simplexml_load_file($file);    
        $article_name = $article->LV_ARTICLES_DESCRIPTIONANDMEASURE->LV_ARTICLES_LANG_NL;  
        $article_specification = $article->LV_ARTICLES_SPECIFICATION->LV_ARTICLES_LANG_NL;
        $article_price_incl = number_format((float)$article->LV_ARTICLES_PRICE_SHOW, 2, '.', '');
        $article_shortinfo = $article->LV_ARTICLES_SHORTMEMO->LV_ARTICLES_LANG_NL;
        $article_image = $article->LV_ARTICLES_PICTUREZOOM;
    }
}

?>

<html>
<body>

<div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Naam:</li><li><?php echo $article_name;?></li></ul></div>
<div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Specificaties:</li><li><?php echo $article_specification;?></li></ul></div>
<div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Prijs inclusief BTW:</li><li><?php echo $article_price_incl;?></li></ul></div>
<div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Omschrijving:</li><li><?php echo $article_shortinfo;?></li></ul></div>
<div style="align:center;"><img src="images/<?php echo $article_image; ?>"></div>
</body>
</html>




Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$files
= scandir('articles/');
foreach($files as $file) {
        $article = simplexml_load_file($file);    
        $article_name = $article->LV_ARTICLES_DESCRIPTIONANDMEASURE->LV_ARTICLES_LANG_NL;  
        $article_specification = $article->LV_ARTICLES_SPECIFICATION->LV_ARTICLES_LANG_NL;
        $article_price_incl = number_format((float)$article->LV_ARTICLES_PRICE_SHOW, 2, '.', '');
        $article_shortinfo = $article->LV_ARTICLES_SHORTMEMO->LV_ARTICLES_LANG_NL;
        $article_image = $article->LV_ARTICLES_PICTUREZOOM;
?>

            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Naam:</li><li><?php echo $article_name;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Specificaties:</li><li><?php echo $article_specification;?></li></ul></div>
            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Prijs inclusief BTW:</li><li><?php echo $article_price_incl;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Omschrijving:</li><li><?php echo $article_shortinfo;?></li></ul></div>
            <div style="text-align:center;"><img src="images/<?php echo $article_image; ?>"></div>
<?php
}
?>


Toevoeging op 01/10/2018 23:24:46:

Als ik $file echo krijg ik als output dit:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
...article_1.xmlarticle_2.xmlarticle_3.xml etc.
Gewijzigd op 02/10/2018 14:15:12 door Bryan De Baar
 
- Ariën  -
Beheerder

- Ariën -

01/10/2018 23:54:22
Quote Anchor link
Dat klopt, want dat zijn ook de bestandsnamen in de array.

Verder output je nu HTML i.p.v. XML.
 
Bryan De Baar

Bryan De Baar

02/10/2018 00:23:53
Quote Anchor link
Hi Ariën,


Dat klopt, ik heb dit gedaan om te kijken of alle informatie klopt en echo deze dan binnen html.
Hoe krijg ik deze loop nu aan het draaien?
 
Jop B

Jop B

02/10/2018 20:11:01
Quote Anchor link
Bryan,

Probeer dit eens

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$files
= glob('articles/*');
foreach($files as $file) {
        $article = simplexml_load_file($file);    
        $article_name = $article->LV_ARTICLES_DESCRIPTIONANDMEASURE->LV_ARTICLES_LANG_NL;  
        $article_specification = $article->LV_ARTICLES_SPECIFICATION->LV_ARTICLES_LANG_NL;
        $article_price_incl = number_format((float)$article->LV_ARTICLES_PRICE_SHOW, 2, '.', '');
        $article_shortinfo = $article->LV_ARTICLES_SHORTMEMO->LV_ARTICLES_LANG_NL;
        $article_image = $article->LV_ARTICLES_PICTUREZOOM;
?>


            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Naam:</li><li><?php echo $article_name;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Specificaties:</li><li><?php echo $article_specification;?></li></ul></div>
            <div clas="name" style="font-size:22px; width:100%; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Prijs inclusief BTW:</li><li><?php echo $article_price_incl;?></li></ul></div>
            <div clas="specs" style="font-size:22px; width:100%; background-color:#f7f7f7; margin:12px 0px;"><ul style="list-style:none; width:400px; margin:0 auto;"><li style="font-weight:bold;">Omschrijving:</li><li><?php echo $article_shortinfo;?></li></ul></div>
            <div style="text-align:center;"><img src="images/<?php echo $article_image; ?>"></div>

<?php
}
?>
 
Bryan De Baar

Bryan De Baar

02/10/2018 20:20:56
Quote Anchor link
Thank Jop B,

Dit werkt nu kan ik de informatie omzetten naar een Magento XML en importeren.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.