I've got xml that looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<products xmlns="http://domain.dev/schema" xmlns:ns2="http://api.domain.dev/schemas">
<header>
<owner>TEST</owner>
</header>
<brand>
<product brandCode="code">
<sizeGridCode>M</sizeGridCode>
<productCategoryAttributes>
<productCategoryAttribute key="longDescription">TEST</productCategoryAttribute>
</productCategoryAttributes>
<LINES>
<productLine>
<productLineId>ASDF</productLineId>
<brandColourName>GreASDFy</brandColourName>
<colourCodes>
<colourCode>ASDF</colourCode>
</colourCodes>
<composition>
<compositionComponent>
<material/>
</compositionComponent>
</composition>
<articles>
<article>
<articleActivationDate>2017-11-20T16:14:15.159Z</articleActivationDate>
<active>true</active>
<brandArticleId>asdfasdf</brandArticleId>
<ean>asdfasdf</ean>
<id>asdfasdf</id>
<articleMedia>
<media>
<ns2:mediaType>image</ns2:mediaType>
<ns2:mediaURL>default_image</ns2:mediaURL>
<ns2:sortOrder>1</ns2:sortOrder>
</media>
</articleMedia>
<categoryAttributes>
<categoryAttribute key="size">XS</categoryAttribute>
</categoryAttributes>
</article>
</articles>
</productLine>
</LINES>
</product>
</brand>
</products>
When I decode this like this:
$xml = simplexml_load_string(
Storage::get($path),
"SimpleXMLElement", LIBXML_NOCDATA
)->registerXPathNamespace("ns2", "http://api.domain.dev/schemas");
$json = json_encode($xml);
return json_decode($json,TRUE);
I receive everything within an array except the <media>
things. Obviously this
is because media has a namespace:
<ns2:mediaType>
How do I make sure I get the ns2:mediaType
data aswell? Because right now I get an empty array?
-- EDIT --
When I add registerXPathNamespace
it's not working. Please see above the edit.