Answer the question
In order to leave comments, you need to log in
How to convert one XML to another?
There is a task : to import products into Opencart from XML using an extension.
The problem is that the file format that the OpenCart extension asks for does not match the one generated by the customer's buh.prog. For unknown reasons, the customer cannot change the format of the generated file.
It was decided to write a small PHP converter that would take the customer's file and generate a file that the extension could read correctly.
So. There is an incoming XML with a list of products like this:
<?xml version="1.0" encoding="UTF-8"?>
<SHOP>
<SHOPITEM>
<NAME>Product 1</NAME>
<PRODUCT_ID/>
<Quantity>5</Quantity>
<MODEL>Product 1 Model</MODEL>
<SKU>302942275</SKU>
<SIZE>XL</SIZE>
</SHOPITEM>
<SHOPITEM>
<NAME>Product 1</NAME>
<PRODUCT_ID/>
<Quantity>6</Quantity>
<MODEL>Product 1 Model</MODEL>
<SKU>302942275</SKU>
<SIZE>2XL</SIZE>
</SHOPITEM>
<SHOPITEM>
<NAME>Product 1</NAME>
<PRODUCT_ID/>
<Quantity>7</Quantity>
<MODEL>Product 1 Model</MODEL>
<SKU>302942275</SKU>
<SIZE>3XL</SIZE>
</SHOPITEM>
<SHOPITEM>
<NAME>Product 2</NAME>
<PRODUCT_ID/>
<Quantity>5</Quantity>
<MODEL>Product 2 Model</MODEL>
<SKU>302942278</SKU>
<SIZE>XL</SIZE>
</SHOPITEM>
</SHOP>
<?xml version="1.0" encoding="UTF-8"?>
<SHOP>
<SHOPITEM>
<NAME>Product 1</NAME>
<PRODUCT_ID/>
<Quantity>2</Quantity>
<MODEL>Product 1 Model</MODEL>
<SKU>302942275</SKU>
<OPTIONS>
<OPTION>
<NAME>Size</NAME>
<VALUE>M</VALUE>
<QUANTITY>1</QUANTITY>
</OPTION>
<OPTION>
<NAME>Size</NAME>
<VALUE>L</VALUE>
<QUANTITY>3</QUANTITY>
</OPTION>
<OPTION>
<NAME>Size</NAME>
<VALUE>XL</VALUE>
<QUANTITY>1</QUANTITY>
</OPTION>
<OPTION>
<NAME>Size</NAME>
<VALUE>2XL</VALUE>
<QUANTITY>2</QUANTITY>
</OPTION>
</OPTIONS>
</SHOPITEM>
</SHOP>
Answer the question
In order to leave comments, you need to log in
the most correct is xslt transformations, because it was specifically designed to convert one XML document to another ... this will be the fastest solution, but IMHO mosk can be broken with these transformations and their syntax
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question