Here's a sample XML structure:
<Products>
<Product>
<Id>1</Id>
<Name>Product 1</Name>
<Category>MEN</Category>
<Category>Women</Category>
<Product>
<Product>
<Id>2</Id>
<Name>Product 2</Name>
<Category>MEN2</Category>
<Category>Women2</Category>
<Product>
</Products>
And I want the file like this:
<Products>
<Product>
<Id>1</Id>
<Name>Product 1</Name>
<CategoryName>MEN:Women</CategoryName>
<Product>
<Product>
<Id>2</Id>
<Name>Product 2</Name>
<CategoryName>MEN:Women</CategoryName>
<Product>
</Products>
So basically it will search through the nodes in products. If it finds "Category", it will change the name to "CategoryName" and concatenate all the sub-sequent category node values into a single one separated by semicolon.
So I have wrote this small PHP, but not sure how to get this to work.
<?php
$xmlFile = "test.xml" //assume the contents are in the file
$xml = simplexml_load_file($xmlFile);
foreach($xml as $item)
{
$name = $item->Product;
if($name->count()) //check if its a "product" node
{
foreach($item as $i)
{
$category = $i->Category;
}
}
}
?>
Can someone point me to the right direction? I haven't much worked with XML.